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

Selecting a View according to the data type. Is this right?

$
0
0

Hello:

Recently, I asked for a way for selecting a view according to a data type for a ListView. I would never find the info about DataTemplateSelector.
Now I'm trying to do the same, but with a view within a ContentPage.

I didn't find any clue, so what I did was the next:
Having these models

public class BaseModel { public int type { get; set; }}

public class Data1Model : BaseModel { public int valueInt { get; set; }}
public class Data2Model : BaseModel { public string valueString { get; set; }}

I created a BaseModel variable on the ViewModel (with the private and public version, the OnPropertyChanged...).
So, I added this to the XAML:

XAML <ContentView x:Name="dataContentView" BindingContext="{Binding myBaseModel}" BindingContextChanged="ChangedBindingData"> </ContentView>

And wrote this on code behind:

CSHARP private void ChangedBindingData (object sender, EventArgs e) { Models.BaseModel data = (Models.BaseModel)dataContentView.BindingContext; switch (data.type) { case 2: dataContentView.Content = new Views.Data2View() { Margin = new Thickness(3), BindingContext = dataContentView.BindingContext }; break; default: dataContentView.Content = new Views.Data1View() { Margin = new Thickness(3), BindingContext = dataContentView.BindingContext }; break; } }

Amazingly, it works, but I don't think it's the right way to do it. I looked for another way to do it, with Templates or whatever other class that could help, but I didn't find any clue to follow. Maybe I'm not writting the right words in the search box, but the thing is, after several hours of searching, this is the best I can come up with.
So, am I right? Is there a better way to do it?

Thanks, and sorry for my 'newbiness' ^^U


Plugin.Geofence not showing notifications

$
0
0

Hello, I am using the NuGet: https://github.com/CrossGeeks/GeofencePlugin for doing some geofencing, and for some reason it doesn't show notifications on enter/stay/exit. Everything else seems to work. Notifications work tho, I tried using a notifications nuget and everything is going nice. Any ideas?

How to do design Mobile screens on the basis mobile Screen Sizes?

$
0
0

plz give solution ..................
Thank U!

Transparent png and TapGestureRecognizer

$
0
0

Hi again,
I'm about to start to convert an ios app we have from Swift to Xamarin. One main concern I have is that this is a very visual application filled with button in odd shapes. As it works today this buttons are pngs with transparent background and only the visible part of the images are recognized as clickable area.

I've tried to recreate this in Xamarin but as I feard the whole box of the image are reacting to the tapped event including the transparent parts. Is there some way to solve this?

/magnus

App breaks after navigating to many pages.Can anyone help?

$
0
0

I have set largeheap true in manifest file and in android properties set heap to 1G

Still application breaks

How can we use .aar files in xamarin.forms Android project?

$
0
0

I want to use .aar files in xamarin.forms android project. I tried with Binding Library, but unable to access classes from .aar file. Can any one suggest me how to do that?
Thanks in Advance.

How to open PDF or TXT file in default app on Xamarin Forms

$
0
0

I am going to open document using default app in Xamarin Forms. I tried already this approach but it doesn't work for me and I am not sure what is the reason.

Device.OpenUri(new Uri(FILE_PATH));

Please give me great solution if anyone knows how to handle it. Thanks.

FontAwesome Label: Here's how!

$
0
0

Here's how you'll use the new FontAwesome label (Any Graphic font will work, but FontAwesome is Awesome):

var coolLabel = new FontAwesomeIcon(FontAwesomeIcon.Icon.Gear)

Here's how to set it up.

Download the FontAwesome font and unzip it. Rename the ttf to FontAwesome.ttf. Note the Case of the name. Copy it to Android /Assets and mark as a BundleAsset. Copy to iOS /Resources and mark as BundleResource and "Copy Always". In iOS edit the info.plist and add this:

  <key>UIAppFonts</key>
  <string>FontAwesome.ttf</string>

Now that we have the font in our projects we need to tell Android, and ONLY Android how to get to the Font. Here's a renderer you can just drop in FontAwesomeIconRenderer.cs:

[assembly: ExportRenderer(typeof(FontAwesomeIcon), typeof(FontAwesomeIconRenderer))]

namespace AAA.Android.Renderers
{
    /// <summary>
    /// Add the FontAwesome.ttf to the Assets folder and mark as "Android Asset"
    /// </summary>
   public  class FontAwesomeIconRenderer: LabelRenderer
    {
       protected override void OnElementChanged(ElementChangedEventArgs<Label> e)
       {
           base.OnElementChanged(e);
           if (e.OldElement == null)
           {
               //The ttf in /Assets is CaseSensitive, so name it FontAwesome.ttf
               Control.Typeface = Typeface.CreateFromAsset(Forms.Context.Assets, FontAwesomeIcon.Typeface + ".ttf");
           }
       }
    }
}

Here's the Label for your common UI project:

namespace AAA.Common.Views.Shared.FontAwesome
{
    public class FontAwesomeIcon : Label
    {
        //Must match the exact "Name" of the font which you can get by double clicking the TTF in Windows
        public const string Typeface = "FontAwesome";  

        public FontAwesomeIcon(string fontAwesomeIcon=null)
        {
            FontFamily = Typeface;    //iOS is happy with this, Android needs a renderer to add ".ttf"
            Text = fontAwesomeIcon;
        }

        /// <summary>
        /// Get more icons from http://fortawesome.github.io/Font-Awesome/cheatsheet/
        /// Tip: Just copy and past the icon picture here to get the icon
        /// </summary>
        public static class Icon
        {
            public static readonly string Gear = "";
            public static readonly string Globe = "";
        }
    }
}

8badf00d on some iOS devices

$
0
0

Hi,

I have submitted my app to the App Store and it has the Crash Analytics enabled from the app centre in it as well.

My problem is that some users are complaining that the app gets stuck on startup and crashes after 20 seconds.

I have received some of their logs (available at https://pastebin.com/jFZEYXTg ) but all I can see is that it is generating an 8badf00d error!

I have checked my code and the OnStart() method is async and is returning immediately!

The problem is that on my own iPhone X the app loads in less than 3 seconds and I have tested it on many other devices and I can say on some random devices, this problem is happening.

I am really wondering what has gone wrong!

How to notify when hit bottom of a Listview?

$
0
0

I'm trying to create a listview that loads items, then loads more items when you scroll to the bottom of the list.

I have all the code already for retrieving my data using paging.

I just can't seem to find an event for hitting the bottom of a listview.

I'm looking for an MVVM solution for this that works across android and iOS. Is there such a thing?

Firebase Auth in Xamarin.Forms?

$
0
0

Hello. I am experimenting with login/register things and I am wondering if it is possible to do it in Xamarin Forms not only in Xamarin.Android of Xamarin.iOS. Haven't found a lot of documentation and what I've found seem not really clear or outdated.

UI tests navigation between pages

$
0
0

Hi.
How can I write a UI test that will wait for my app to navigate to another page?
I try to use "_app.WaitForElement" to wait for an element that has in destiny, but I get a TimeoutException, eg:

[Test]
public void QuandoInformarLoginSenhaCorretos_ExibirMapa()
{
    _app.WaitForElement(e => e.Marked("btnLogar"));
    _app.Tap(t => t.Marked("txtUsuario"));
    _app.EnterText("fake");
    _app.Tap(t => t.Marked("txtSenha"));
    _app.EnterText("fake");
    _app.Tap(t => t.Marked("btnLogar"));// this line is to do a login in app and call new page
    _app.WaitForElement(e => e.Marked("frmMapa")); // this line search a element e destiny page, but I get a TimeoutException
    _app.Repl();
}

thank you.

How to show Android Fragment(SupportWalletFragment) in Xamarin.Forms

$
0
0

I'm trying to add Google Pay to my application. The only tutorial I found is https://blog.xamarin.com/bring-android-pay-to-your-apps-with-stripe/ . I need to create an android SupportWalletFragment and show it to user:

var walletFragment = SupportWalletFragment.NewInstance (WalletFragmentOptions.NewBuilder ()
    .SetEnvironment (WalletConstants.EnvironmentSandbox)
    .SetMode (WalletFragmentMode.BuyButton)
    .SetTheme (WalletConstants.ThemeLight)
    .SetFragmentStyle (new WalletFragmentStyle ()
        .SetBuyButtonText (BuyButtonText.BuyWithGoogle)
        .SetBuyButtonAppearance (BuyButtonAppearance.Classic)
        .SetBuyButtonWidth (Dimension.MatchParent))
    .Build ());

walletFragment.Initialize (WalletFragmentInitParams.NewBuilder ()
    .SetMaskedWalletRequest (maskedWalletRequest)
    .SetMaskedWalletRequestCode (LOAD_MASKED_WALLET_REQ_CODE)
    .Build ());

SupportFragmentManager.BeginTransaction ()
    .Replace (Resource.Id.frameFragment, walletFragment).Commit ();

How can I do it in Xamarin.Forms application?
Can I use customRenderer?
Maybe better code examples or tutorials exist?

Bind SelectedItem in ListView to element in another page

$
0
0

I am new to Xaml, and have been scouring the web for examples, but so far all I have found is binding viewmodels commands to elements on the same page. But what I would like to do is bind elements on one page to trigger an event on another page. What I have is a Main Page:

<TabbedPage.Children>
    <pages:MapPage"  >
        <pages:MapPage.BindingContext>
            <viewModels:MapViewModel/>
        </pages:MapPage.BindingContext>
    </pages:MapPage>

    <pages:LayersPage">
        <pages:LayersPage.BindingContext>
            <viewModels:LayersViewModel/>
        </pages:LayersPage.BindingContext>-->
    </pages:LayersPage>

</TabbedPage.Children>

The Map Page holds a custom SkiaSharp control that loads maps. The LayersPage holds a listview with possible layers to load:

<ContentPage.Content>
    <StackLayout>
        <ListView x:Name="listView" 
                  ItemsSource="{Binding Layers}" 
                  Header="{Binding Intro}"
                  Footer="{Binding Summary}"
                  ItemTapped="OnItemTapped">
            <ListView.HeaderTemplate >
                <DataTemplate>
                    <StackLayout Orientation="Horizontal" 
        Padding="10,5,5,10"
        BackgroundColor="Yellow">
                        <Label Text="~~"/>
                        <Label Text="{Binding .}"/>
                        <Label Text="~~"/>
                    </StackLayout>
                </DataTemplate>
            </ListView.HeaderTemplate>
            <ListView.ItemTemplate>
                <DataTemplate>
                    <TextCell Text="{Binding Name}" Detail="{Binding Description}"></TextCell>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </StackLayout>
</ContentPage.Content>

So when a layer is selected on the listview, it should raise a command/event to the MapPage, and subsequently the Map element to load layer (string) selected. I am trying to use MVVM, and I can get the list view to raise an even on the "ItemTapped" event in the LayersPage, but I am now unsure how to send that string to the MapViewModel, or even the element that has a method called AddLayer(string layer).

So I have read lots of article about commands and binding, and I feel slightly confident on binding to elements within the page, but not to other pages. Any help or step in the right direction would be appreciated.

Why am I receiving a Xamarin.Forms.Xaml.XamlParseException?

$
0
0

Hi everyone,

I'm trying to reference a XAML styles resource dictionary from another project, but I'm getting the following exception:
Xamarin.Forms.Xaml.XamlParseException: Position 9:18. Type theme:StyleLibrary not found in xmlns clr-namespace:Polytrack.Styles.XAML;assembly=Polytrack.Styles

I'm referencing this XAML style (called StyleLibrary) in my App.xaml:

<?xml version="1.0" encoding="utf-8" ?>
<Application x:Class="Allumobile.BusinessLayer.App"
xmlns:theme="clr-namespace:Polytrack.Styles.XAML;assembly=Polytrack.Styles">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<theme:StyleLibrary/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>

This code doesn't give any errors and when I type "theme:", VS's IntelliSense automatically finds "StyleLibrary".

My StyleLibrary.xaml is in a referenced project called Polytrack.Styles and in a folder called XAML:
<?xml version="1.0" encoding="utf-8" ?>
<ResourceDictionary x:Class="Polytrack.Styles.XAML.StyleLibrary">
<!-- Some XAML styles here -->
</ResourceDictionary>

The Allumobile.BusinessLayer project references the Polytrack.Styles project. Am I missing something?


Failed to read FormsViewGroup.dll with debugging symbols

$
0
0

So... this error started popping up when I try building as Release on Android.

Failed to read 'C:\Users\gferreira\Documents\Source\Repos\EcoMindMobile\EcoMind\EcoMind.Android\obj\Release\81\linksrc\FormsViewGroup.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.

The details:

1>Mono.Cecil.Cil.SymbolsNotMatchingException: Symbols were found but are not matching the assembly
1>   at Mono.Cecil.ModuleDefinition.ReadSymbols(ISymbolReader reader, Boolean throwIfSymbolsAreNotMaching)
1>   at Mono.Cecil.ModuleReader.ReadSymbols(ModuleDefinition module, ReaderParameters parameters)
1>   at Mono.Cecil.ModuleReader.CreateModule(Image image, ReaderParameters parameters)
1>   at Mono.Cecil.ModuleDefinition.ReadModule(Disposable`1 stream, String fileName, ReaderParameters parameters)
1>   at Mono.Cecil.ModuleDefinition.ReadModule(String fileName, ReaderParameters parameters)
1>   at Mono.Cecil.AssemblyDefinition.ReadAssembly(String fileName, ReaderParameters parameters)
1>   at Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.ReadAssembly(String file)

This same error repeats 3 times throughout the build (found in the build log with Diagnostic MSBuild settings).

It seems to be something related to Xamarin Forms itself and linking, though after more hours than I'd like to admit sinked into this, I have no idea how to solve it. It's just warning, and it builds/works despite this, however just disregarding the warning doesn't seem like the best idea.

I didn't change anything in the release configs or nuget packages, it just started appearing out of the blue last week when I archived the solution.

The seemingly classic mscorlob conflict also appears, though this one has been happening for longer (I've been ignoring it as there doesn't seem to be an actual fix?)

1>There was a conflict between "mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e" and "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089".
1>    "mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e" was chosen because it was primary and "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" was not.

Could they be related? There are Xamarin.Forms references to both versions for some reason. Any ideas? I'm inclined to just start ignoring the warning, because so far things are still working.

DatePicker Binding Not Binding

$
0
0

Hi, So I'm still new in Xamarin Forms and has been asked to develop an app wherein it keeps track of schedules of the business. Such as when the business started, the business ended and so on.

But before I explain what's happening here's the code for the view

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="xamarin.com/schemas/2014/forms"
             xmlns:x="schemas.microsoft.com/winfx/2009/xaml"
             x:Class=""
             xmlns:local=""
             Title="Lock" Icon="">
    <ContentPage.Content>
        <StackLayout>
            <StackLayout Padding="10">
                <TableView Intent="Data">
                    <TableRoot>
                        <TableSection Title="Schedule">
                            <ViewCell>
                                <StackLayout Orientation="Horizontal" Padding="20,0">
                                    <Label Text="Sched Start" HorizontalOptions="StartAndExpand" VerticalOptions="Center" FontSize="Small"></Label>
                                    <DatePicker Format="MM/dd/yyyy" Date="{Binding SchedStartDate, Mode=TwoWay}" HorizontalOptions="EndAndExpand"></DatePicker>
                                    <TimePicker HorizontalOptions="EndAndExpand"></TimePicker>
                                </StackLayout>
                            </ViewCell>

                            <ViewCell>
                                <StackLayout Orientation="Horizontal" Padding="20,0">
                                    <DatePicker Format="MM/dd/yyyy" Date="{Binding SchedEndDate, Mode=TwoWay}" HorizontalOptions="EndAndExpand"></DatePicker>
                                    <TimePicker HorizontalOptions="EndAndExpand"></TimePicker>
                                </StackLayout>
                            </ViewCell>
                        </TableSection>
                    </TableRoot>
                </TableView>
            </StackLayout>
        </StackLayout>
    </ContentPage.Content>
</ContentPage>

This one is the code for the ViewModel

    public DateTime? SchedStartDate
            {
                get
                {
                    return this.schedStartDate;
                }

                set
                {
                    if (value != this.schedStartDate)
                    {
                        this.schedStartDate = value;
                        OnPropertyChanged();
                    }
                }
            }

            public DateTime? SchedEndDate
            {
                get
                {
                    return this.schedEndDate;
                }

                set
                {
                    if (value != this.schedEndDate)
                    {
                        this.schedEndDate = value;
                        OnPropertyChanged();
                    }
                }
            }

And I'm calling this in the code behind in OnAppearing() method.

        public async void GetLock (int ID)
                {
                    var result = await MyHttpRequest.GetSchedule(ID);

                    SchedStartDate = DateTime.Now;
                    SchedEndDate = DateTime.Now;
                    ActualStartDate = DateTime.Now;
                    ActualEndDate = DateTime.Now;
        }

So what's happening is whenever I run the app the first DatePicker, the one binded to "SchedStartDate" gets populated with the Data from the DB.
But the second one goes to the default.

Things I did:
1. I removed the first datepicker and the second datepicker gets the data from the DB.
2. 100% sure that the data is not default since I checked the data when I debugged.
3. Tried to use the same Binding Field for both DatePickers, but only the first one gets populated with the DB Data.
4. Tried to set the 2 variables to DateTime and it worked, but I would need to have null?

Note: This page is inside the TabbedPage, I doubt that's the issue, but just in case.

Hopefully someone can help me figure this out or did I miss something in the documentation, please let me know.
Any help is appreciated. :smiley:

How to use MessagingCenter correctly?

$
0
0

Hello. Im using Xamarin.Forms Crossplatform with .NET library if that matters.

App.xaml.cs

MainPage = new NavigationPage(new MainPage());

MainPage.xaml.cs

Im using a method here. I have a TapGestureRecognizer on a Frame:

void OnTestTapped(object sender, EventArgs args)
{
//...
MessagingCenter.Send<MainPage, string>(this, "Message", "TryThis");
Navigation.PushAsync(new AnotherPage());
}

AnotherPage.xaml

<StackLayout>
<Label x:Name="labelName"/>
</StackLayout>

AnotherPage.xaml.cs:

public partial class AnotherPage : ContentPage
{
    string helper;
    public AnotherPage()
    {
        InitializeComponent();
        MessagingCenter.Subscribe<MainPage, string>(this, "Message", (sender, helper) =>
        {
            this.helper = helper;
            labelName.Text = this.helper;
        });
    }
}

When Debugging I can see that label.Text has a value of "TryThis". But when looking on the App there is no text. Where is my mistake here and how can I fix it?

Why is a page's OnDisappearing() method not called when the app closes?

$
0
0

Hi,

I'm surprised that a ContentPage's OnDisappearing method is not being called when the (iOS) app closes, how should I persist data or fire off a message to the server?

Exception: "LoadTemplate should not be null" (Xamarin 1.4.0.6341)

$
0
0

Hello,
I have updated to Xamarin 1.4.0.6341 today, it all works fine but when I open
a ScrollView with a ListView inside the App crashes and the Error "System.InvalidOperationException: LoadTemplate should not be null"
appears.
When I remove the ListView from the ScrollView, the Page and the Controls onto are shown and the App don't crashes.

Thanks in advance

Viewing all 89864 articles
Browse latest View live


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