Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all 58056 articles
Browse latest View live

How to place an Absolute Layout inside a Stack Layout

$
0
0

Hello there! So what I'm trying to accomplish is the following: I have a scrollview with a stack layout inside it, and I'd like to create multiple absolute layouts which each wrap around a group of elements, which would then be added into the stack layout. For the sake of clarification consider something like Instagram's homepage, where you have Posts composed of an Image, the User's Name on top of It, and the comments section beneath it. Ideally, I'd like to create those "post" objects and have them wrapped inside an absolute layout, which in turn would be stacked inside a stacklayout, which would be scrollable (inside a scroll view). Now, I'm not sure if the way I'm implementing it is the best way to do so, but any help would be appreciated.

Code looks something like this

`

    <StackLayout x:Name="StackLayout_Container"
                 HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"
                 Spacing="10"
                 Padding="5"
                 ></StackLayout>

</ScrollView>`

I then create CardObjects as needed with each containing its own absolute layout, and later have them added to the StackLayout. This works, but for some reason the views inside the absolutelayout (images, labels ..etc) end up being too small and aren't positioned correctly, and the scrollview isn't scrollable. Any help is appreciated


ScrollView not updating when elements are changed on Android

$
0
0

I have a ContentPage, with a ScrollView that has a StackLayout with a couple of nested StackLayouts.

Essentially:

public class Widgets : ContentPage
{
    StackLayout layout;
    public Widgets()
    {
        layout = new StackLayout()
        {
            VerticalOptions = LayoutOptions.FillAndExpand,
            Orientation = StackOrientation.Vertical
        };

        var Widget = new Wiget();
        layout.Children.Add(Widget.Render());
        //Widget.Render() returns a StackLayout with some other UI elements, it also loads some items from the web and adds them to the stacklayout. 

        var Widget2 = new Wiget2(); //Same idea...
        layout.Children.Add(Widget2.Render());

        Content = new ScrollView()
        {
            HorizontalOptions = LayoutOptions.FillAndExpand,
            VerticalOptions = LayoutOptions.FillAndExpand,
            Content = layout
        };
    }
}

When the Widget class finishes loading the web items, and adds them to the stacklayout, the new elements are not rendered, in fact any change to the UI does not get rendered. The widgets display a Loading icon while the items are loading, this is displayed properly and the loading icon disappears when loading is complete, but the new elements do not show up.

This appears this when running on Android, the ScrollView and related Widget elements work properly on iOS. Admittedly I can only try Android on the emulator so not sure if it is an issue with it. I am using the built-in Android_Accelerated_Nougat with API version 25. (7.1.1)

iOS Binding Library in Xamarin Forms project

$
0
0

I have a binding library that works fine in a Xamarin iOS project, but if I try to use it in a Xamarin Forms project, the application crashes with a SIGSEGV every time as soon as the library is accessed.

Are there any special concerns to take into account when using a binding library with a Forms app?

How to use OnIdiom to reference OnPlatform data in XAML?

$
0
0

I'm trying to set different text size, for each different platform & form factor in the application wide ResourceDictionary

<OnPlatform x:Key="myfontsize-phone" x:TypeArguments="x:Double" iOS="20" Android="20" WinPhone="30"/> <OnPlatform x:Key="myfontsize-tablet" x:TypeArguments="x:Double" iOS="40" Android="40" WinPhone="60"/> ... <OnIdiom x:Key="myfontsize" x:TypeArguments="x:Double" Phone="{StaticResource myfontsize-phone}" Tablet="{StaticResource myfontsize-tablet}"/>

and in my page XAML, i just call it with

<Label Text="SomeText" FontSize="{StaticResource myfontsize}"/>

The code above compile alright, but on run time I encountered with "System.InvalidCastException: Specified cast is not valid" in my page's InitializeComponent(). If I take out the reference to the and reference to the item instead, it will work alright.

This is what I get in the debug log, which isn't much help
09-01 20:56:01.292 E/mono (15401): Unhandled Exception: 09-01 20:56:01.292 E/mono (15401): System.InvalidCastException: Specified cast is not valid. 09-01 20:56:01.292 E/mono (15401): at (wrapper dynamic-method) System.Object:be601f56-8ff2-4aab-a41a-aababab502f5 (intptr,intptr,intptr) 09-01 20:56:01.292 E/mono (15401): at (wrapper native-to-managed) System.Object:be601f56-8ff2-4aab-a41a-aababab502f5 (intptr,intptr,intptr) 09-01 20:56:01.294 E/mono-rt (15401): [ERROR] FATAL UNHANDLED EXCEPTION: System.InvalidCastException: Specified cast is not valid. 09-01 20:56:01.294 E/mono-rt (15401): at (wrapper dynamic-method) System.Object:be601f56-8ff2-4aab-a41a-aababab502f5 (intptr,intptr,intptr) 09-01 20:56:01.294 E/mono-rt (15401): at (wrapper native-to-managed) System.Object:be601f56-8ff2-4aab-a41a-aababab502f5 (intptr,intptr,intptr)

Any clue on what might have gone wrong?

how to highlight code syntax in Xamarin.Forms Text editor

$
0
0

Hello
I would like to know how can I highlight code in Xamarin.Forms Text Editor like in web-application we highlight output code of textbox using Highlight.js in HTML view?
Is this possible in Xamarin?
I need to place some formatted code with syntax highlighting in my xamarin.forms application.

Adding the badge count to the toolbar icon?

$
0
0

Can any one please help me how to add the count to the tool bar icon in xamarin.forms?

Thanks in advance.

I have a problem with Grid on Android simulator

$
0
0

Hello.
Can you help me?
I have XAML with simple Grid:

<Grid HorizontalOptions="Fill" VerticalOptions="Center" Padding="40" RowSpacing="10" ColumnSpacing="10">
    <Grid.RowDefinitions>
        <RowDefinition Height="2*" />
        <RowDefinition Height="*" />
        <RowDefinition Height="*" />
        <RowDefinition Height="*" />
        <RowDefinition Height="*" />
        <RowDefinition Height="*" />
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>
    <Label TextColor="White" 
           HorizontalOptions="Center"
           FontAttributes="Bold" 
           FontSize="50"
           Grid.Row="1"
           Grid.Column="0"
           Grid.ColumnSpan="3" Text="12345"></Label>

    <Button FontSize="30" TextColor="#28282c" BackgroundColor="#fff" BorderRadius="30" Text="1" Grid.Column="0" Grid.Row="3"></Button>
    <Button FontSize="30" TextColor="#28282c" BackgroundColor="#fff" BorderRadius="30" Text="2" Grid.Column="1" Grid.Row="3"></Button>
    <Button FontSize="30" TextColor="#28282c" BackgroundColor="#fff" BorderRadius="30" Text="3" Grid.Column="2" Grid.Row="3"></Button>

    <Button FontSize="30" TextColor="#28282c" BackgroundColor="#fff" BorderRadius="30" Text="4" Grid.Column="0" Grid.Row="4"></Button>
    <Button FontSize="30" TextColor="#28282c" BackgroundColor="#fff" BorderRadius="30" Text="5" Grid.Column="1" Grid.Row="4"></Button>
    <Button FontSize="30" TextColor="#28282c" BackgroundColor="#fff" BorderRadius="30" Text="6" Grid.Column="2" Grid.Row="4"></Button>

    <Button FontSize="30" TextColor="#28282c" BackgroundColor="#fff" BorderRadius="30" Text="7" Grid.Column="0" Grid.Row="5"></Button>
    <Button FontSize="30" TextColor="#28282c" BackgroundColor="#fff" BorderRadius="30" Text="8" Grid.Column="1" Grid.Row="5"></Button>
    <Button FontSize="30" TextColor="#28282c" BackgroundColor="#fff" BorderRadius="30" Text="9" Grid.Column="2" Grid.Row="5"></Button>

    <Button FontSize="30" TextColor="#28282c" BackgroundColor="#fff" BorderRadius="30" Text="0" Grid.Column="1" Grid.Row="6"></Button>

    <Button FontSize="30" TextColor="#28282c" BackgroundColor="#96ca2d" BorderRadius="30" Text="Dial" Grid.ColumnSpan="3" Grid.Row="7"></Button>
</Grid>

When I run this XAML on iOS simulator, I haven't problems. But when I run on Android, I have problems with grid height.

Having issues in android on logout flow

$
0
0

Hi,

I have a Xamarin forms app which is based on MasterDetailPage, whereas it's Detail is a TabbedPage.
When app loads I set the Main page as follows:

    MainPage = IsUserLoggedIn ? new MainPage() : (Page) new LogInPage();

Upon login everything works fine.

I've recently added a logout button located on MasterPage's Master, and handled it as follows (in LogOutPage):

    protected override void OnAppearing()
    {
        App.IsUserLoggedIn = false;

        App.Current.MainPage = new LogInPage();
    }

On iOS it works great, directing the user to the LogInPage.

However in Android I get the following error: (which refers to this line: 'App.Current.MainPage = new LogInPage();')

'Java.Lang.IllegalStateException: Recursive entry to executePendingTransactions'

I'll appreciate any help on that.


xamarin forms Device.Starttimer vs .net standard System.Timers

$
0
0

I wonder if somebody has a experience with .net standard system timer and compare with device.starttimer. I have the feeling that Xamarin forms device timer is not optimized and having often high memory usage although i handle return false correctly which supposed to dispose the timer. Does anybody used System.Timers as we have .net standard now? I wonder how are they converted into native libraries?

Package restore failed. Rolling back package changes

$
0
0

Can anyone please help me
Why I am geting the error "Package restore failed. Rolling back package changes" for project name, While i am installing the plugin .current activity. idea? Please let me know.

Thanks in dvance.

Master Detail - Missing Page List in Release Builds

$
0
0

I've got a master detail page setup. The hamburger menu slides in a list of pages available. Each page opens the same ContentPage but with a different title and ID, which then grabs data from a SQLite DB.

The list is generated in the following manner

using System;
using System.Collections.Generic;

using Xamarin.Forms;

namespace ui.main
{
    public partial class MasterPage : ContentPage
    {
        public sqlite.subscribedTopicsDatabase _topics = new sqlite.subscribedTopicsDatabase();
        public ListView ListView { get { return listView; } }

        public MasterPage()
        {

            InitializeComponent();
            SetupUI();
        }

        /// <summary>
        /// Setups the user interface.
        /// </summary>
        async void SetupUI()
        {

            // Get topics
            var topics = await _topics.GetAllsubscribedTopics();

            var masterPageItems = new List<MasterPageItem>();

            masterPageItems.Add(new MasterPageItem
            {
                Title = "All",
                Topic = -1,
                //IconSource = "contacts.png",
                TargetType = typeof(AllTopicsPage)
            });

            for (int i = 0; i < topics.Count; ++i)
            {
                System.Diagnostics.Debug.WriteLine("I have topic: " + topics[i].name);
                masterPageItems.Add(new MasterPageItem
                {
                    Title = topics[i].name,
                    Topic = topics[i].apiID,
                    TargetType = typeof(TopicDetailPage)
                });
            }

            listView.ItemsSource = masterPageItems;
        }
    }
}

On a debug build, the items appear, on a release build, they do not. See screenshots.

Debug Build
Debug Build

Release Build
Release Build

What could be causing this?

Xamarin Forms: Button event sequence and Command

$
0
0

Hi,

I have a simple custom button that adds a pressed animation effect. However, I have found that it would sometimes still be busy with the animation when it fires the Command bound to this control, which results in the weird freezing artefact of the animation.

The sequence of events seems to be Pressed, Released(Command), , Clicked but because my animation runs async, the pressed is triggered while the animation still runs, the Command is invoked while the animation is still running.

To try and fix this, I have intercepted the Command, and I then invoke it myself.

        public RoundedButton() : base()
        {
            this.Pressed += AnimateButtonPress;
            this.Released += OnReleased;
        }

        private async void AnimateButtonPress(object sender, EventArgs e)
        {
            try
            {
                ButtonCommand = Command;
                Command = null;
                if (Animate &&
                    !isAnimating)
                {
                    isAnimating = true;
                    await this.ScaleTo(1.1, 70, Easing.Linear);
                    await this.ScaleTo(1, 30, Easing.BounceOut);
                    isAnimating = false;
                }
                if (ButtonCommand != null &&
                    ButtonCommand.CanExecute(CommandParameter))
                {
                    ButtonCommand.Execute(CommandParameter);
                }
            }
            finally
            {
                Command = ButtonCommand;
            }
        }

Is this a good idea? Or is there any other way of doing it

How to Bind Listview under CarouselView in Xamarin Forms?

Resource identifier has already been used in this assembly

$
0
0

Following the steps from the Xamarin Forms intro, and running into the error "the resource identifier 'Monkey.ios.MonkeyPage.xaml' has already been used in this assembly (CS1508). Ideas?

How to enable a real windows-phone (Lumia930) for debugging in VS2013...?

$
0
0

Hi all
I have bought a (brandnew) Nokia Lumia930 (to be able to debug on real device in VS2013).
As I don't have found any information's in the forum, how to connect a real windows phone, I have searched the internet (maybe this information's are helpful for other's)...

First, you have to "unlock" your windows-phone for development.
Therefore you (first) must have a registered MS-Account.
Then you have to connect the Windows Phone with the PC and to load a tool from the WP-Toolkit to "unlock" your Phone (here you need your MS-Account).
Details to register the phone under this link:
msdn.microsoft.com/library/windows/apps/ff769508(v=vs.105).aspx#BKMK_UsingtheWindowsPhoneDeveloperRegistrationTool

Further information's for trouble-shooting under this link:
msdn.microsoft.com/de-DE/library/windows/apps/ff402565(v=vs.105).aspx#BKMK_device

I have "unlocked" my device.
Also the service "IpOverUsbSvc" (described under the second link above) is running on my machine.
The (also under the second link described) tool "IpOverUsbEnum", I don't have found, as I also don't have found the whole directory "C:\Program Files (x86)\Common Files\Microsoft Shared\Phone Tools\CoreCon\11.0\Bin\".

I can see the Phone in the Windows-Filemanager (and have access to it).

Unfortunately, I don't can see the device in VS2013 and are not able use the device for debugging...

Under VS 2013 (Update 2) I have installed:
Windows Phone SDK 8.0 - DEU
Windows Phone 8.1 SDK-Integration (1.0)

To the project (nuget) I have installed:
WindowsPhone Toolkit V. 4.2013.08.16

Do I miss something...?

Help please....
Thanks a lot


Display lyrics while playing song in xamarin forms

$
0
0

I made audio player in xamarin forms(PCL) as Follows:

Player.xaml(PCL):

     public player(Entity.File entity)
        {
            InitializeComponent();
            _file = entity;
            DependencyService.Get<iFile>().PlayFile(entity.FullPath);
        }

Files.cs(Android):

    public bool PlayFile(string filePath)
        {
            if(currentFile != filePath)
            {
                if (_mediaPlayer != null)
                {
                    _mediaPlayer.Stop();
                }
                _mediaPlayer = MediaPlayer.Create(global::Android.App.Application.Context, Android.Net.Uri.Parse(filePath));
                _mediaPlayer.Start();
                var file = rootDirectory.GetFiles(".lrc", SearchOption.AllDirectories).FirstOrDefault();
                _mediaPlayer.AddTimedTextSource(file.FullName, "application/octet-stream");
                _mediaPlayer.SetVolume(100, 100);
                currentFile = filePath;
            }
            return true;
        }   

It works fine in play and pause but I am unable to display lyrics which is attached in addtimedTextSource file. I have to display lyrics while play the song.

Anyone have idea about displaying lyrics of audio in xamarin forms?

Propertychanged delegate in BindableProperty is called twice with datatrigger

$
0
0

I know that this question was already asked but I was not able to find a solution for my problem.

My question is this: I've a bindable property in a custom control that is exposed to show a text (the pagetitle), and I need that this text is cutted when the view is in portrait.
I want that this bindable property takes its value from a property inherited from a base (PageTitle) and than that a converter do the work to cut the word when it's needed.
I have created a datatrigger to fire that converter, but I think that I misunderstanded how it works, because on the first rotation all works as expected, but from the second rotation the Propertychanged delegate is fired twice and I didn't understand why.

I was able to solve this specific problem using a Label binded to the property that I use as parameter in my converter, but it's not a clean way to achieve the result and I would understand if something is wrong with my datatrigger and what.

I've a created a simple demo project downloadable from here that explains better what I mean, in the first row I've inserted the control with the bindable property that doesn't work, and in the thirth the solution that works but that it's surely not the best practice to do it.

Thank you in advance

Memory Management with MVVM in Xamarin Forms

$
0
0

I am developing one mobile application using Xamarin Forms. My Application navigates in such a way where initially LoginPage is my MainPage i.e.

MainPage = new LoginPage();

After successful login, i reassign MainPage with master detail page i.e.

MainPage = new MasteDetailPage();

In Master page, i have one list and on click of list item, i navigate to different content pages i.e.

this.Detail = new NavigationPage(new DetailPage());

Once i click on logout which is one of the list item of master page, i again re-assign MainPage with LoginPage i.e.

MainPage = new LoginPage();

This is how navigation works in my application.

Each page is having their own view model which contains business logic. Once my viewmodel initializes, it initializes few class level objects and commands which i need to nullify in order to avoid memory consumption because it initialize every time when my page initializes.

So my question is, when i should remove these class level objects from viewmodel ? Do i need to pop each pages from navigation stack manually, once i navigate to another page.

Each page has OnDisappearing() method. Should i remove/pop that page from navigation stack on page OnDisappearing() method ?

Please help.

Installing CocosSharp.Forms via NuGet leads to Build Errors

$
0
0

Hi everyone, I just created an empty Xamarin.Forms project (shared code) in Visual Studio 2017. The project built and ran fine (debug x86, UWP, local machine).

I then added the CocosSharp.Forms and CocosSharp NuGet packages for Android, iOS, and UWP.

Now the project does not build (same configuration), with errors:

  • Type universe cannot resolve assembly: Xamarin.Forms.Platform.WinRT, Version=1.5.0.0, Culture=neutral, PublicKeyToken=null
  • Cannot resolve Assembly or Windows Metadata file 'Xamarin.Forms.Platform.WinRT.dll'

I'm not sure how to interpret this. Does CocosSharp.Forms not support UWP?

Cheers,
Thomas

Versions:
CocosSharp.Forms Android, iOS, UWP v 1.7.1
CocosSharp Android, iOS, UWP v 1.7.1
Xamarin.Forms Android, iOS, UWP v 2.3.3.193

label binding

$
0
0

Can any one please help me on this? I have a label like this Wallet order :210541 .Wallet order is constant but the order id number is getting from the server. so my question is how to write the xaml code in xamarin.forms in mvvm? I tried with label span but i could not able to get that.

Thanks in advance.

Viewing all 58056 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>