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

Configuring Azure App Service social login and Essentials.WebAuthenticator

$
0
0

Hello everyone,

I'm completely new to the world of Azure and Xamarin and I'm trying to build a little Xamarin.Forms app (I'm building it just for Android) with a back-end hosted on Azure App Service and one of the features I'd like to implement the most is the social authentication with Facebook at least.

I set up the social login in the app service and it actually works in the browser, still I can't manage to make it work with Xamarin.Essentials WebAuthenticator. Basically I made it open the browser correctly but after authenticating there I don't return to the app. I tried using post_login_redirect_url and this fixed returning to the app.. but only without a token.

The redirect url I use is correctly saved in Authentication settings of App Service, so I'm wondering what part I am missing. I might have messed with the native client app registration, but honestly I didn't even understand if that's needed or not.

Can anyone please send me a guide or explain here how to setup the whole thing to work? I'm literally going crazy because everything I manage to find is about Azure Mobile Apps, which has been shut down as I understand.

Many thanks in advance!


Remove Flyout icon and its space

$
0
0

I need to remove Flyout icon image in my Xamarin.Forms app and to move title to left so that icon space also does not appear.
Please help to achieve it.

I want to move the image displayed in SkiaSharp by tapping, swiping, or pinching. I am displaying

Using custom font in Xamarin adds extra spacing below and above the text

$
0
0

Hello

I would like to use custom ( imported ttf ) font in Xamarin. I use Xamarin.Forms 4.4, I put ttf into Assets folder of my android project.
But when I display some text with this font, text is displayed with extra spacing above and below text ( red bordered areas on pic)

The VerticalTextAlignment works fine, but I don't know what are these spaces ( I guess these spaces are gaps between top and ascent values of font , and bottom and descent values of font) and how can I remove them? I tried set font metrics with fontforge (on Element -> Font info->OS/2->Metrics pane) but no effect.

I tried other ttf font, that font has extra spacing too, but size of spacing above and below text was different.

Xaml for upper Sample text:
<Label Text="Sample text" FontFamily="font.ttf#font name" FontSize="26" LineHeight="12" FontAttributes="Bold" VerticalOptions="End" VerticalTextAlignment="Start" BackgroundColor="Aqua" Padding="0" Margin="0" HeightRequest="100"/>

Xaml for other Sample text:
<Label Text="Sample text" FontFamily="font.ttf#font name" FontSize="26" LineHeight="12" FontAttributes="Bold" VerticalOptions="End" VerticalTextAlignment="Start" BackgroundColor="Aqua" Padding="0" Margin="0"/>

Thanks for your help

Is there a way of getting all the used NuGet packages in a Xamarin.Forms project from the code?

$
0
0

Title...

I need to show all of the NuGet packages used in my app in the legal info. Is there a way of doing it programmatically so that I don't have to come back each time we use a new NuGet package?

[xfx combox] Dynamically insert an item that doesn't exist in the ItemSource

$
0
0

So the list contains elements: ["Company1", "Company2", "Company3"].

When the user's start typing, the popup shows up with those elements. However, I want user to be able to insert the new item: "Company4", but the user is not able to do it!

Media Element crash when navigating away from page on Ios

$
0
0

I am getting Media Element disposing exception when I navigate back to a previous page from a page where I have my Media Element.

The managed Managed Stacktrace:

          at <unknown> <0xffffffff>
          at ObjCRuntime.Messaging:void_objc_msgSend_IntPtr <0x00007>
          at AVFoundation.AVPlayer:ReplaceCurrentItemWithPlayerItem <0x0005b>
          at Xamarin.Forms.Platform.iOS.MediaElementRenderer:Dispose <0x002b7>
          at Foundation.NSObject:Dispose <0x00023>

My steps to reproduce were:
Push new page with MediaElement. Click play on video.
Click back to pop page.
Page does pop but UI becomes unresponsive.

my code is:

public partial class SermonsMediaPlayer : ContentPage
            {
                private Sermon Sermon;

                public SermonsMediaPlayer(Sermon selectedSermon)
                {
                    InitializeComponent();

                    if (selectedSermon is null)
                    {
                        Sermon = new Sermon();
                    }

                    Sermon = selectedSermon;
                    BindingContext = Sermon;

                }

                async void Back_Clicked(object sender, EventArgs args)
                {
                    // release media resources
                    if (mediaPlayer.CurrentState == MediaElementState.Playing)
                    {

                        mediaPlayer.Stop();
                        await Navigation.PopModalAsync();
                    }

                    await Navigation.PopModalAsync();
                }

                protected override void OnDisappearing()
                {
                    base.OnDisappearing();
                }
            }


        <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="xxxViews.SermonsMediaPlayer">
            <ContentPage.ToolbarItems>
                <ToolbarItem Text="Back" Clicked="Back_Clicked" />
            </ContentPage.ToolbarItems>
            <ContentPage.Content>
                <Grid>
                    <MediaElement x:Name="mediaPlayer" Source="{Binding Url}" AutoPlay="False"
                      ShowsPlaybackControls="True" KeepScreenOn="False" />
                </Grid>
            </ContentPage.Content>
        </ContentPage>

Using visual state manager with a controltemplate

$
0
0

Hi everyone, apologies if this has been answered already. I've got a xamarin forms shell app and I'm trying to use visual state manager on a page that has a ControlTemplate called BasicPageTemplate set in the ContentView. When the GoToState method fires it's crashing with a targetName cannot be null error, which doesn't happen if I remove the ControlTemplate property. This suggests to me that there's an issue with the binding context but I can't work out how to get around it. My (simplified) xaml is below. Have I missed something obvious or is this an issue with forms? Many thanks.

<?xml version="1.0" encoding="UTF-8"?>
<views:BasePage xmlns="http://xamarin.com/schemas/2014/forms" 
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="MyApp.Views.VisualStateTestPage"
             x:Name="visualStateTestPage"
             xmlns:views="clr-namespace:MyApp.Views;assembly=MyApp"
                Shell.TabBarIsVisible="False" Shell.FlyoutBehavior="Disabled">
    <ContentView x:Name="contentView">
        ControlTemplate="{StaticResource BasicPageTemplate}">                              
            <StackLayout x:Name="stackLayout">
                <VisualStateManager.VisualStateGroups>
                    <VisualStateGroup Name="ValidityStates">
                        <VisualState Name="Valid">
                            <VisualState.Setters>
                                <Setter TargetName="entry"
                                        Property="Entry.BackgroundColor"
                                        Value="Red" />
                            </VisualState.Setters>
                        </VisualState>
                        <VisualState Name="Invalid">
                            <VisualState.Setters>
                                <Setter TargetName="entry"
                                        Property="Entry.BackgroundColor"
                                        Value="Blue" />
                            </VisualState.Setters>
                        </VisualState>
                    </VisualStateGroup>
                </VisualStateManager.VisualStateGroups>
                <Button x:Name="button" Clicked="button_Clicked"></Button>
                <Entry x:Name="entry" ></Entry>
            </StackLayout>                            
        </ScrollView>
    </ContentView>
</views:BasePage>

How to call an azure function in a secure way

$
0
0

We have a list of azure functions that we would like to call from the xamarin forms app.(user should not be prompted a login,all silent calls)

Functions have AuthorizationLevel=Function and therefore requires a function Key.

Where do you store the functionKey? definetely not in the app, I have read that the vault is not the way to do it.

How do you do it? is SAS the way to do it? or vault?
cannot find anything as guidance

any suggestions

What is the best way to show a ContentPage in a new window in UWP?

$
0
0

Hi all,
I have been able to create a new window in UWP using DI and display a XF page within it, but having a few issues. Has anyone done this?

The issues are:
How to set the new window size?
I can set the size using: ApplicationView.GetForCurrentView().TryResizeView(new Windows.Foundation.Size(500, 800));
Unfortunately the XF page doesn't resize within it, and subsequent runs of the app show the main window at this size as well until I have uninstalled the app.

Opening a 3rd window crashes the app with:
A COM call to an ASTA was blocked because the call chain originated in or passed through another ASTA. This call pattern is deadlock-prone and disallowed by apartment call control.

The UWP code I am using to display the new window is as follows:

        var newView = CoreApplication.CreateNewView();
        var newViewId = 0;

        await newView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
        {
            var frame = new Windows.UI.Xaml.Controls.Frame();
            frame.Navigate((ContentPage) page);

            Window.Current.Content = frame;
            Window.Current.Activate();

            newViewId = ApplicationView.GetForCurrentView().Id;
            var viewShown = await ApplicationViewSwitcher.TryShowAsStandaloneAsync(newViewId);
            ApplicationView.GetForCurrentView().TryResizeView(new Windows.Foundation.Size(500, 800));
        });

Does anyone have a better solution for displaying XF pages in new windows on UWP?

Thanks
John

how set Loading image - Error image to Image

$
0
0

I don't want to use this plugin ffimageloading

Introduce new tools

In a XF app DisplayAlert is hanging in UWP project?

$
0
0

DisplayAlert is hanging only in UWP and only in one app. Other apps don't have any issue. Even for this app no issues with Android and iOS.

I am calling it as follows:

await DisplayAlert("Pick a Photo", "No photo selected.", "OK");

What is missing here?

Created a perfect Exapandable ListView (iOS) row by NOT using ForceUpdateSize, what gives?

$
0
0

So I've been struggling with creating an expandable ListView row. It seems people have been having a lot of trouble with this in the past. Recently a new ViewCell method called "ForceUpdateSize" was added. This allowed me to create a custom ViewCell which called "ForceUpdateSize" and changed the Height on itself when a certain event was fired on the BindingContext object. This did work and the item would fold in and out but it was lagging and strange bugs would occur (iOS) where you could see other items flickering, moving up/down and so on. Also I could not change the default animations.

For those interested however I just solved this on iOS by using a CustomRenderer to get hold of the UITableView. I then stored that reference and could via another class call the method "_uiTableView.ReloadRows(...)" instead of ForceUpdateSize(). Now it works perfectly and the animation looks great + no lagging! I can also pick from all the available iOS animations.

So my question is, what is the reason for this? Is the Xamarin.Forms implementation not as simple as calling ReloadRows? Does it invalidate the full layout etc?

Anyway if you want a perfect result for now you should do similair to how I did it.

CMS For Content and Products Data

$
0
0

Ok So I have my mobile design common on nice with my designer and I am codding the xaml myself.
But what do most people use to drive the user content is their a nice cms kicking about that helps with the textual content of apps so that
Is their any online hosted platforms one would suggest that provide api level access to data?

Change image according item value in listview

$
0
0

Hi friends, I searched more than a week on the internet but I didn't find anything helpful.

I've a listview in my app with a lot of informations. I would like to change the image if some condition is true do you know?

My listview.ItemSource is a query from the database and I would like to change the image according its category type. If category type is 1 the image should be image1.png, if category type is 2 the image should be image2.png and so on.

In C# webform I would do it on databing event handler, but I didn'f find anything related in listview on xamarin. Is there someone that can help to reach out this goal?

That's my XAML

<ListView x:Name="lvProducts" HasUnevenRows="True" BackgroundColor="White">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                        <ViewCell.View>
                            <Grid>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto"/>
                                    <RowDefinition Height="Auto"/>
                                    <RowDefinition Height="Auto"/>
                                </Grid.RowDefinitions>

                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto" />
                                    <ColumnDefinition Width="Auto" />
                                </Grid.ColumnDefinitions>

                                <Image Aspect="AspectFill" HeightRequest="60" Grid.RowSpan="3" Source="{Binding imgCategory}" Margin="10"/>

                                <!--Linha um, o stacklayout mantem tudo na mesma linha-->
                                <StackLayout Grid.Row="0" Grid.Column="1" Orientation="Horizontal">
                                    <Label Text="{Binding numProduct}" FontAttributes="Bold" TextColor="#ff0000" HorizontalTextAlignment="Start"></Label>
                                    <Label Text=": " FontAttributes="Bold" TextColor="#ff0000" HorizontalTextAlignment="Start"></Label>
                                    <Label Text="{Binding nomeProduct}" FontAttributes="Bold" TextColor="#ff0000" HorizontalTextAlignment="Start"></Label>
                                </StackLayout>

                                <!--Linha dois, o stacklayout mantem tudo na mesma linha-->
                                <StackLayout Grid.Row="1" Grid.Column="1" Orientation="Horizontal">
                                    <Label Text="{Binding numCategory}" FontSize="12" TextColor="#5e5e5e" ></Label>
                                    <Label Text=" - " FontSize="12" TextColor="#5e5e5e"></Label>
                                    <Label Text="{Binding nomeCategory}" FontSize="12" TextColor="#5e5e5e" ></Label>
                                </StackLayout>

                                <!--Linha dois, o stacklayout mantem tudo na mesma linha-->
                                <StackLayout Grid.Row="2" Grid.Column="1"  Orientation="Horizontal">
                                    <Label Text="{Binding categoryType}" FontSize="10" FontAttributes="Italic"></Label>
                                </StackLayout>

                            </Grid>
                        </ViewCell.View>
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>

That's my Code Behind:

private void fillListViewProduct ()
        {
            SQLiteConnection dataBase = new SQLiteConnection(_databasePath);

            List<Products> selectItems = dataBase.Query<Products>("SELECT numProduct, nomeProduct, numCategory, nomeCategory, categoryType FROM tabproducts");
            lvProducts.ItemsSource = selectItems;

        }

Any help will be appreciated.

Kind regards,

Claudionir Queiroz

PS.: Sorry for my bad English, I hope you can understand it.


ListView behaviour in UWP project

$
0
0

I've just started working with Xamarin Forms and I'm trying to wrap my head around a couple of things that are (not) happening relating to a bound ListView, hopefully someone can shed some light on this for me.

    private Item _SelectedItem;        
    public Item SelectedItem;
    {
       get => _SelectedItem;
       set
       {
          _SelectedItem; = value;
          NotifyPropertyChanged("SelectedItem");
        }
    }

    public ObservableCollection<Item> ItemsList { get; set; }
    public ICommand RemoveItemCommand { get; private set; }


    public MyViewModel()
    {
       RemoveItemCommand = new Command(RemoveItem, CanRemoveItem);
    }

    private void RemoveItem()
    {
       ItemsList.Remove(SelectedItem);
    }

    private bool CanRemoveItem()
    {            
       return SelectedItem != null;
       //return true;
    }

And the Xaml:

  1. When a row is selected there is no visual indication that it has been selected (ie. row is not highlighted)

  2. When a row is selected, the SelectedItem property in my ViewModel contains the selected correct object, but the
    CanRemoveItem property of the command is never set to true so the button is always disabled. However, RemoveItem method and button work when CanRemoveItem is manually set to true.

Is this expected behaviour or am I missing the mark somewhere?

Rg.plugins Popup with FreshMVVM callback issue

$
0
0

When the savecommand is triggered I do not get the Event OnOrderItemUpdated fired to the calling PageModel within a Tabbed Page.

//UpdateOrderPageModel Event

public event EventHandler OrderItemUpdated;

    protected virtual void OnOrderItemUpdated(OrderItemEventArgs e)
    {
        EventHandler<OrderItemEventArgs> handler = OrderItemUpdated;
        handler?.Invoke(this, e);
    }

//Save Command in UpdateOrderPageModel Class
var e = new OrderItemEventArgs(new OrderItem());
OnOrderItemUpdated(e);

//Calling Tabbed Page Model

public OrderItem SelectedOrderItem
{
get { return _selectedOrderItem; }
set {
_selectedOrderItem = value;
Task.Run(async () => await PopoUpdatePage());
RaisePropertyChanged(nameof(SelectedOrderItem));
}
}

    private async Task PopoUpdatePage()
    {
        //Private Property UpdateOrder 
        this.UpdateOrder = FreshIOC.Container.Resolve<UpdateOrderPageModel>();
        UpdateOrder.OrderItemUpdated += U_OrderItemUpdated;          
        await CoreMethods.PushPopupPageModel<UpdateOrderPageModel>(SelectedOrderItem,true);
    }

This is not working OnOrderItemUpdated not firing ..

Why is my binding not working when I want to insert data?

$
0
0

Hi!I am struggling with an MVVM problem as I don't understand why my data is not saved into the sqlite database.I looked over MVVM examples and initially I wanted to use the model class which i reference it in the vm so that i can bind it directly into the view.Unfortunately the values were null.I tried to assign the values of the model to the properties in vm like this:
public Users user {get;set;} public string Name { get{ return user.Name;} set{user.Name = value;} OnNotifyPropertyChanged(); }
This didn't work as it gave me a null error upon initialization of the page regarding the values.As far as I understood you have to create an instance of the vm into the contentpage before doing anything else and that was exactly what I did:
<StackLayout.BindingContext> <l:RegistrationViewModel/> </StackLayout.BindingContext>

Now I am passing the values from the vm to the model into the constructor and the vm values are not null,instead when i try to insert the data,it gives me null values.This is my ViewModel:

` public class RegistrationViewModel : BaseViewModel
    {
        public int Id { get; set; }
        private string name;
        private string email;
        private string phone;
        private string password;
        private string confPassword;
        RegistrationPage page;
      //  public ICommand RegisterCommand { get; private set; }
        public RegistrationViewModel()
        {

        }
        public RegistrationViewModel(RegistrationPage page)
        {
            user = new Users();  
        Id = user.Id;
        name = user.Name;
        phone = user.Phone;
        email = user.Email;
        password = user.Password;
         confPassword = user.ConfPassword;
            this.page = page;

       //   RegisterCommand = new Command(async () => await Register());
        }
        public ICommand RegisterCommand => new Command(async () => await Register());
        public async Task Register()
        {
            bool isUserAccept = await Application.Current.MainPage.DisplayAlert("Add contact", "Do you want to register?", "ok", "Cancel");
            if (isUserAccept)
            {

                App.Data.AddUser(user);
                await page.DisplayAlert("Registration Succesful", "You have been registered" + "" + name, "OK");
            }
       /*     if (user == null)
            {
                await page.DisplayAlert("Registration went wrong", "Please complete all fields", "OK");
            }*/

        }

        public string Name
        {
            get { return name; }
            set
            {

                    name = value;
                OnPropertyChanged("Name");
            }
        }
       public Users user { get; set; }

        public string Email
        {

            get { return email; }
            set
            {

                    email = value;
                OnPropertyChanged("Email");
            }
        }
        public string Phone
        {
            get { return phone; }
            set
            {
                    phone = value;
                OnPropertyChanged("Phone");
            }
        }
        public string Password
        {
            get { return password; }
            set
            {

                    password = value;
                OnPropertyChanged("Password");
            }
        }
        public string ConfPassword
        {
            get { return confPassword; }
            set
            {

                   confPassword = value;
                OnPropertyChanged("ConfPassword");
            }
        }
    }`

The View:

    `<?xml version="1.0" encoding="utf-8" ?>
    <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
                 xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                 xmlns:d="http://xamarin.com/schemas/2014/forms/design"
                 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:l="clr-namespace:Edu.VM"
                 mc:Ignorable="d"
                 x:Class="Edu.Views.RegistrationPage">
        <ContentPage.BindingContext>
            <l:RegistrationViewModel/>
        </ContentPage.BindingContext>
        <StackLayout HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" Padding="20,0">
            <Entry IsPassword="False" x:Name="userName" Placeholder="Name" Text="{Binding Name, Mode=TwoWay}" PlaceholderColor="Black" HeightRequest="40"/>
            <Entry IsPassword="False" x:Name="userEmail" Placeholder="Email" Text="{Binding Email, Mode=TwoWay}" PlaceholderColor="Black" HeightRequest="40"/>
            <Entry IsPassword="False" x:Name="userPhone" Placeholder="Phone" Text="{Binding Phone, Mode=TwoWay }" PlaceholderColor="Black" HeightRequest="40"/>
            <Entry IsPassword="True" x:Name="userPassword" Placeholder="Password" Text="{Binding Password, Mode=TwoWay}" PlaceholderColor="Black" HeightRequest="40"/>
            <Entry IsPassword="True" x:Name="userConfPassword" Placeholder="Confirm Password" Text="{Binding ConfPassword, Mode=TwoWay}" PlaceholderColor="Black" HeightRequest="40"/>
            <Button x:Name="registerUser" Command="{Binding RegisterCommand,Mode=TwoWay}" Text="Register"/>
        </StackLayout>
    </ContentPage>`

The Model:

    ` [Table("Users")]
       public class Users
        {
            [AutoIncrement, PrimaryKey]
            public int Id { get; set; }
            [NotNull]
            public string Name { get; set; }
            [NotNull]
            public string Phone { get; set; }
            [NotNull]
            public string Password { get; set; }
            [NotNull]
            public string ConfPassword { get; set; }
            [NotNull]
            public string Email { get; set; }
            public Users() { }
        }`

Can someone help me understand what am I doing wrong?Best regards!

Display Xamarin Font Icons From Stored Data

$
0
0

Hello! What is the best way to display font icons with data being pulled from a web service? I want to store the value of the icon and display the icon similar to the rest of the information, but with a custom font icon.

I have a xamarin forms app working with data from a webservice successfully. Here is my model.

public class TypeModel
{
    [PrimaryKey]
    public int pType { get; set; }

    public int fDepartment { get; set; }

    public string Title { get; set; }

    public string Description { get; set; }

    public string Icon { get; set; }

    public string Version { get; set; }

}

I also got the font icons working successfully like the tutorial at [1]: https://montemagno.com/using-font-icons-in-xamarin-forms-goodbye-images-hello-fonts/ I got my icons stored under this class. Trying to transition to managing these values with web service or array if I have too now.

public const string IconCheckMark = "\uf12c";

public const string IconSearchGlass = "\uf349";

public const string IconQuestionMark = "\uf2d6";

public const string IconQuestionCircle = "\uf2d7";

But here is where my problem starts. My ViewModel is doing the work to create the collection. How do I assign a value that will display and match correctly.

public ObservableCollection<TypeModel> TypesCollection { get; set; }

TypesCollection.Clear();

IEnumerable<TypeModel> types = await DataSource.GetTypes();

foreach (var key in types)
{
    \\Original value doesn't display correctly, shows like \U f 1 2 c when debugging on emulator
    \\key.Icon = key.Icon;

    \\Works and displays correctly but static data displays one icons for all
    \\key.Icon = "\uf12c";

    \\Works and displays correctly but static data displays one icons for all
    \\key.Icon = FontClass.IconCheckMark;

    TypesCollection.Add(key);    
}

Nice and simple after that for the xaml files.

<ResourceDictionary>

    <OnPlatform x:Key="IconFonts" x:TypeArguments="x:String">

        <On Platform="iOS" Value="Material Design Icons"></On>

        <On Platform="Android" Value="IconFonts.ttf#Material Design Icons"></On>

        <On Platform="UWP" Value="/Assets/IconFonts.ttf#Material Design Icons"></On>

    </OnPlatform>

</ResourceDictionary>

<Label FontFamily="{StaticResource IconFonts}" Text="{Binding Icon}"></Label>

Navigation.PopAsync not freeing Page

$
0
0

I'm having a problem in a project where pages I pop from my Navigation controller aren't freed or collected by the GC on iOS. I eventually run out of memory and crash. I figured I had reference cycles blocking but I couldn't come up with any solution.

I've put together a small project allowing you to push and pop pages from the Navigation stack. If you take a look at HeapShot or Instruments you'll see the objects just keep adding up - nothing is released.

Am I doing something wrong or is this a bug?

Tested against the latest Xamarin.Forms library, and with SGen and the reference counting extension enabled.

Viewing all 89864 articles
Browse latest View live


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