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

PropertyChanged is not null although we don't subscribe any function to it. How come?

$
0
0

I implement INotifyPropertyChanged and it works fine.

There is something I don't understand though: PropertyChanged is a an event, which means it is a delegate.

Before we invoke event/delegate we need them to point on some function/eventHundler ("Subscribe") -
otherwise the event will be null.

How is it, that here we declare an event, I didn't subscribe no one to this event, and still - it is not null.

public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged([CallerMemberName] string propertyName = "")
{
   var changed = PropertyChanged;
    if (changed == null)   //It seems for me, this should be null for ever.  
       return;
    changed.Invoke(this, new PropertyChangedEventArgs(propertyName));
}~~~~

Xamarin.Forms Best Practices for Handling Data Streams

$
0
0

Hello, I am new to xamarin.forms & I was having issues when handling data streams
I am also a firebase user in which we can create a streams of data where whenever data is updated on the server, every client subscribed to it gets updated.
Note everytime a stream is started / subscribed to, A read is performed & basically it increases Database Reads.
I use github /f-miyu/Plugin.CloudFirestore this plugin to use firestore.

Problem:
Currently I start & stop streams in OnAppearing & OnDisappearing methods but my concern is when a stream is going-on on a current page & A new page is pushed, the stream stops & resumes when that new page it is popped. Which is obvious as I am using OnAppearing & OnDisappearing.
But What I want is that these stream should stop only when the current page is popped (When the page object is actually destroyed) but stream should be going on even when a new page is pushed above it.

Reason:
When a user navigates on the new page for say 5 times, all these 5 times stream on 1st page is started & stopped 5 times which actually results is 5 full database reads which also in results costs 5 times more.

How do I start the stream only once and stop it only when the page is popped / destroyed.

Solutions Tried:
Stopping the stream in the destructor of the ViewModel or The ContentPage - Don't know why but I don't see any logs which I added in those destructors & streams are not closed, even when app is closed by tapping the back button

// ListenerRegistration
private IListenerRegistration dataListnerRegistration;

// To start the stream
Debug.WriteLine("Starting stream");
dataListnerRegistration = DatabaseHelper.GetLast7DaysData()
                    .AddSnapshotListener(updateListByDocuments);

// To stop the stream
Debug.WriteLine("Stoping stream");
dataListnerRegistration.Remove();
dataListnerRegistration = null;

iOS 13.0 Broke MasterDetailPage on iPads?

$
0
0

I have noticed that after updating iOS to v13.0, the MasterDetailPage is broken on iPads but it's still working on iPhones and Androids.
By broken I mean the whole page is white, without content.


The only way to fix this is to update Xamarin.Forms to the latest v4.2+.

The problem is that some other packages are not compatible (XF broke something else after v4.0) so I cannot update XF yet.
The App Store is rejecting my app because it shows a white screen on iPads with iOS 13.0+....so I would have to stop targeting iPads!

Try for yourself, here is a basic sample repo with MasterDetail page (the default Xamarin Forms template with MasterDetailPage).
https://github.com/stesvis/MasterDetailTest2

The same happens with Prism MasterDetailsPage:
https://github.com/stesvis/MasterDetailTest

  • iPhones: works
  • iPad -> iOS 12.2: works
  • iPad -> iOS 13.0: white screen

Any solution for this HUGE headache?

On Shell Custom renderer have problem?

$
0
0

On Shell Custom renderer have problem? when I build the project my flyout menu and my bottom navigation tabbar background color are not working ?

custom renderer for bottom navigation tab font size smaller and bigger icon fontsize ? thanks

Project Class

public class CShell: AppShell
{

}

Adroid Class

[assembly: ExportRenderer(typeof(AppShell), typeof(CShellRenderer))]
namespace Goo4.Droid.Renderers
{
public class CShellRenderer : ShellRenderer
{
    public CShellRenderer(Context context) : base(context)
    {
    }
    protected override IShellBottomNavViewAppearanceTracker CreateBottomNavViewAppearanceTracker(ShellItem shellItem)
    {
        return new CBottomNavViewAppearanceTracker();
    }

}


public class CBottomNavViewAppearanceTracker : IShellBottomNavViewAppearanceTracker
{
   public void Dispose()
    {

    }

    public void ResetAppearance(BottomNavigationView bottomView)
    {

    }

    public void SetAppearance(BottomNavigationView bottomView, IShellAppearanceElement appearance)
    {
            IMenu menu = bottomView.Menu;
        for (int i = 0; i < bottomView.Menu.Size(); i++)
        {
            IMenuItem menuItem = menu.GetItem(i);
            var title = menuItem.TitleFormatted;
            SpannableStringBuilder sb = new SpannableStringBuilder(title);

            int a = sb.Length();

            //here I set fontsize 20
            sb.SetSpan(new AbsoluteSizeSpan(11, true), 0, a, SpanTypes.ExclusiveExclusive);

            menuItem.SetTitle(sb);
        }
    }
   }
}

ios Class

[assembly: ExportRenderer(typeof(AppShell), typeof(CShellRenderer))]
namespace Goo4.iOS.Renderers
{
    public class CShellRenderer : ShellRenderer
    {
        public CShellRenderer() : base()
        { }

        protected override IShellTabBarAppearanceTracker CreateTabBarAppearanceTracker()
        {
            return new CTabbarAppearance();
        }
    }

    public class CTabbarAppearance : IShellTabBarAppearanceTracker
    {
        public void Dispose()
        {

        }

        public void ResetAppearance(UITabBarController controller)
        {

        }

        public void SetAppearance(UITabBarController controller, ShellAppearance appearance)
        {

        }

        public void UpdateLayout(UITabBarController controller)
        {

        }
    }
}

Xamarin UI Test Failed: System.InvalidOperationException : Sequence contains no matching element.

$
0
0

I used to be able to run my unit previously, with this configuration in Start Up using Xamarin UI test.
Here’s the setup configuration.

                return ConfigureApp.Android.ApkFile(@"/Users/user101/Develop/Builds/Android/DemoApp.Android.apk")
                                .EnableLocalScreenshots()
                                .DeviceSerial("96891d4831475a4e4a")
                                .StartApp(AppDataMode.Clear);

When I run it now on MAC, on an Android Device, I’m getting a blank screen with this error message.

Error: System.InvalidOperationException : Sequence contains no matching element.

I’m currently using all the latest tools.

Xcode: 11.6
Xamrin.UITest: 3.0.7
Visual Studio for Mac: 8.6.6 (build 11)

Any insights as to why I’m getting this error message?

Thanks.

Sliding up Panel in Xamarin.Forms?

$
0
0

What is the best way to implement the Sliding up Panel used in apps like Google Maps in Xamarin.Forms?

How to create Menu with sub-menu in Hamburger Menu using listview

$
0
0

Hi, I have a menu in masterpage just like this

I have create this menu using listview. Now i need to add sub-menu some of this menu items. how could i do this using listview. Just like below picture

Thanks in advance.

How to apply CSS

$
0
0

How to apply CSS for creating gradient button in xamarin forms
please help!


Start Lottie on ButtonClick

Checkbox and TapGestureRecognizer not work

$
0
0

Why this not work (command is not executed)

<CheckBox Grid.Row="0" Grid.RowSpan="2" Grid.Column="3">
                                    <CheckBox.GestureRecognizers>
                                        <TapGestureRecognizer
                                            Command="{Binding Path=BindingContext.AddRemoveFavorite,
                                            Source={x:Reference Page}}"
                                            CommandParameter="{Binding .}"

                                    </CheckBox.GestureRecognizers>
</CheckBox>

while this work

<Label Text="123" Grid.Row="0" Grid.RowSpan="2" Grid.Column="2">
                                    <Label.GestureRecognizers>
                                        <TapGestureRecognizer
                                            Command="{Binding Path=BindingContext.AddRemoveFavorite,
                                            Source={x:Reference Page}}"
                                            CommandParameter="{Binding .}"

                                    </Label.GestureRecognizers>
                                </Label>

?

How can I handle Checkbox tap?

Main purpose is that Checkbox is in ViewCell in listview that is binding to ObservableCollection. After check/uncheck I will save changing propoerty of object in database.

Saving files to external storage

$
0
0

Hello, everyone! I'm saving a backup from my app's database in SpecialFolder.Personal, it works, but I can't access the file nor move it to another directory, so I wanted to save it directly to the external storage. I already had a DependecyService to get the database location in Android, so I tried to use it to also get the External Storage directory, but when I click to save the backup file and browse in my phone/emulator I can't find it. Here's how I have done:

The class to get the path in the Android Project:

[assembly:Dependency(typeof(Caminho))]
namespace VendasEstoque.Droid.Banco
{
        public string GetPath()
        {
            string caminhoPasta = Android.OS.Environment.ExternalStorageDirectory.Path;

            return caminhoPasta;
        }
}

In the main project I added the following to my DatabaseAcess Class:
string pt = dep.GetPath();

Also, I have a public interface (ICaminho) with the following:

     public interface ICaminho
        {
            string ObterCaminho(string NomeArquivoBanco);
            string GetPath();
        }

Finally, to create the backup file:

            private void BtnBackup_Clicked(object sender, EventArgs e)
            {
                var dep = DependencyService.Get<ICaminho>();
                string db_path = dep.ObterCaminho("database.sqlite");
                string backup_path = Path.Combine(dep.GetPath(), "database.sqlite");

                var origin = File.ReadAllBytes(db_path);
                File.WriteAllBytes(backup_path, origin);

                DisplayAlert("BACKUP", "Backup Created!", "OK");
            }

I appreciate any help. Thanks in advance!

ITMS-90809: Deprecated API Usage-UIWebView

FlyoutItem dynamically loaded

$
0
0

Hello,
Is there any way to bind the items displayed in the shell FlyoutItem? In my app i want to enable to user too add devices after which these devices will be displayed in the Flyout.
Thank you

Xamarin form android scrolling lag ,,,

$
0
0

Hello everyone I have this layout and i am displaying the images from image i have on the android and the ios on ios scrolling works very smoth but android the is some lag while scrolling

<?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:ffimageloading="clr-namespace:FFImageLoading.Forms;assembly=FFImageLoading.Forms"
             xmlns:flv="clr-namespace:DLToolkit.Forms.Controls;assembly=DLToolkit.Forms.Controls.FlowListView"
             mc:Ignorable="d"
           BackgroundImageSource = "backgroundmenu.png"
             FlowDirection="LeftToRight"
             x:Class="ooo.Views.MainPage1">
    <ContentPage.Content>

        <!--BackgroundImageSource = "backgroundmenu.png"-->
        <StackLayout>
            <Grid >

                <Grid.RowDefinitions>
                    <RowDefinition Height="80"/>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition   Width="50" />
                    <ColumnDefinition   Width="*" />
                    <ColumnDefinition   Width="50" />
                </Grid.ColumnDefinitions>

                <ImageButton  Grid.Row="0" Grid.Column="2"  BackgroundColor="Transparent" HorizontalOptions="End" WidthRequest="20" Margin="0,0,15,0" Source="sidemenu.png" x:Name="sidemenuoo" Clicked="sidemenuoo_Clicked" />
                <Image   Grid.Column="1" Grid.Row="0" Source="ooo.png" WidthRequest="100" VerticalOptions="Center" />

            </Grid>
            <flv:FlowListView  SeparatorVisibility="None"  x:Name="MainFrontPageList" HasUnevenRows="True" FlowColumnCount="2" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"   IsPullToRefreshEnabled="False">

                <flv:FlowListView.FlowColumnTemplate>
                    <DataTemplate>
                        <ffimageloading:CachedImage 
                            Margin="0,0,0,0" 
                              WidthRequest="200"
                                    HeightRequest="200"
                                      FadeAnimationEnabled="False"
                                         Source="{Binding UrlImage}" 
                                         CacheType="All"
                             VerticalOptions="Fill"
                                    HorizontalOptions="Center"
                                 >
                            <ffimageloading:CachedImage.GestureRecognizers>
                                <TapGestureRecognizer  Tapped="mashweer_Clicked_1"  CommandParameter="{Binding ClikeLink}" />
                            </ffimageloading:CachedImage.GestureRecognizers>
                        </ffimageloading:CachedImage>
                    </DataTemplate>

                </flv:FlowListView.FlowColumnTemplate>
            </flv:FlowListView>
        </StackLayout>

    </ContentPage.Content>
</ContentPage>



<!--<Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="200"/>
                        <RowDefinition Height="200"/>
                        <RowDefinition Height="200"/>
                        <RowDefinition Height="200"/>
                        <RowDefinition Height="200"/>
                        <RowDefinition Height="200"/>
                    </Grid.RowDefinitions>



                    <ffimageloading:CachedImage  

                                     VerticalOptions="FillAndExpand"
                                     FadeAnimationEnabled="False"
                                    Grid.Row="0" Grid.Column="0"
                                 Aspect="AspectFill"
                                       Source="aa.png"
                                         CacheType="All"
                                     >
                        <ffimageloading:CachedImage.GestureRecognizers>
                            <TapGestureRecognizer  Tapped="mashweer_Clicked_1"   CommandParameter="1" />
                        </ffimageloading:CachedImage.GestureRecognizers>
                    </ffimageloading:CachedImage>



                    <ffimageloading:CachedImage  
                                    Aspect="AspectFill"
                                      FadeAnimationEnabled="False"
                                    Grid.Row="0" Grid.Column="1"

                                         Source="bb.png" 
                                         CacheType="All"
                                     >
                        <ffimageloading:CachedImage.GestureRecognizers>
                            <TapGestureRecognizer  Tapped="mashweer_Clicked_1"  CommandParameter="2" />
                        </ffimageloading:CachedImage.GestureRecognizers>
                    </ffimageloading:CachedImage>





                    <ffimageloading:CachedImage  
                                   Aspect="AspectFill" 
                                 FadeAnimationEnabled="False"
                                   Grid.Row="1" Grid.Column="0"

                                       Source="cc.png" 
                                         CacheType="All"
                                     >
                        <ffimageloading:CachedImage.GestureRecognizers>
                            <TapGestureRecognizer  Tapped="mashweer_Clicked_1" CommandParameter="3" />
                        </ffimageloading:CachedImage.GestureRecognizers>
                    </ffimageloading:CachedImage>




                    <ffimageloading:CachedImage  
                                   Aspect="AspectFill"
                                      FadeAnimationEnabled="False"
                                Grid.Row="1" Grid.Column="1"

                                      Source="oo.png" 
                                         CacheType="All"
                                     >
                        <ffimageloading:CachedImage.GestureRecognizers>
                            <TapGestureRecognizer  Tapped="mashweer_Clicked_1" CommandParameter="4" />
                        </ffimageloading:CachedImage.GestureRecognizers>
                    </ffimageloading:CachedImage>





                    <ffimageloading:CachedImage  
                                    Aspect="AspectFill"
                                    FadeAnimationEnabled="False"
                               Grid.Row="2" Grid.Column="0"

                                     Source="ff.png" 
                                         CacheType="All"
                                     >
                        <ffimageloading:CachedImage.GestureRecognizers>
                            <TapGestureRecognizer  Tapped="mashweer_Clicked_1" CommandParameter="6" />
                        </ffimageloading:CachedImage.GestureRecognizers>
                    </ffimageloading:CachedImage>



                    <ffimageloading:CachedImage  
                                Aspect="AspectFill"
                                    FadeAnimationEnabled="False"
                               Grid.Row="2" Grid.Column="1"

                                   Source="yy.png"
                                         CacheType="All"
                                     >
                        <ffimageloading:CachedImage.GestureRecognizers>
                            <TapGestureRecognizer  Tapped="mashweer_Clicked_1" CommandParameter="5" />
                        </ffimageloading:CachedImage.GestureRecognizers>
                    </ffimageloading:CachedImage>





                    <ffimageloading:CachedImage  
                                   Aspect="AspectFill"
                                    FadeAnimationEnabled="False"
                         Grid.Row="3" Grid.Column="0"
                                    BackgroundColor="Transparent"
                                  Source="ee.png" 
                                         CacheType="All"
                                     >
                        <ffimageloading:CachedImage.GestureRecognizers>
                            <TapGestureRecognizer  Tapped="mashweer_Clicked_1" CommandParameter="8" />
                        </ffimageloading:CachedImage.GestureRecognizers>
                    </ffimageloading:CachedImage>




                    <ffimageloading:CachedImage  
                                   Aspect="AspectFill"
                                    FadeAnimationEnabled="False"
                        Grid.Row="3" Grid.Column="1"
                                    BackgroundColor="Transparent"
                                   Source="pp.png"
                                         CacheType="All"
                                     >
                        <ffimageloading:CachedImage.GestureRecognizers>
                            <TapGestureRecognizer  Tapped="mashweer_Clicked_1" CommandParameter="7" />
                        </ffimageloading:CachedImage.GestureRecognizers>
                    </ffimageloading:CachedImage>



                    <ffimageloading:CachedImage  
                                  Aspect="AspectFill"
                                    FadeAnimationEnabled="False"
                       Grid.Row="4" Grid.Column="0"
                                    BackgroundColor="Transparent"
                                  Source="hh.png"
                                         CacheType="All"
                                     >
                        <ffimageloading:CachedImage.GestureRecognizers>
                            <TapGestureRecognizer  Tapped="mashweer_Clicked_1" CommandParameter="10" />
                        </ffimageloading:CachedImage.GestureRecognizers>
                    </ffimageloading:CachedImage>




                    <ffimageloading:CachedImage  
                                   Aspect="AspectFill"
                                    FadeAnimationEnabled="False"
                     Grid.Row="4" Grid.Column="1"
                                    BackgroundColor="Transparent"
                                  Source="dd.png"
                                         CacheType="All"
                                     >
                        <ffimageloading:CachedImage.GestureRecognizers>
                            <TapGestureRecognizer  Tapped="mashweer_Clicked_1" CommandParameter="9" />
                        </ffimageloading:CachedImage.GestureRecognizers>
                    </ffimageloading:CachedImage>




                    <ffimageloading:CachedImage  
                                 Aspect="AspectFill"
                                    FadeAnimationEnabled="False"
                     Grid.Row="5" Grid.Column="0"
                                    BackgroundColor="Transparent"
                                    Source="tt.png"
                                         CacheType="All"
                                     >
                        <ffimageloading:CachedImage.GestureRecognizers>
                            <TapGestureRecognizer  Tapped="mashweer_Clicked_1" CommandParameter="12" />
                        </ffimageloading:CachedImage.GestureRecognizers>
                    </ffimageloading:CachedImage>





                    <ffimageloading:CachedImage  
                                   Aspect="AspectFill"

                                    FadeAnimationEnabled="False"
                    Grid.Row="5" Grid.Column="1"
                                    BackgroundColor="Transparent"
                                    Source="gg.png"
                                         CacheType="All"
                                     >
                        <ffimageloading:CachedImage.GestureRecognizers>
                            <TapGestureRecognizer  Tapped="mashweer_Clicked_1" CommandParameter="11" />
                        </ffimageloading:CachedImage.GestureRecognizers>
                    </ffimageloading:CachedImage>




                </Grid>-->


Popup Page with Editer multi line not working?

$
0
0

I have description Editer i need to show the complete text but editer not go to the next line and also text is not visible. Following is my code. One more thing my page is Popup page and the property of Autosize is not avilable




            <Entry x:Name="txtDescription" Placeholder="Description" HeightRequest="100"  WidthRequest="10" FontSize="Small" MaxLength="200" HorizontalOptions="FillAndExpand"/>
            <StackLayout Orientation="Horizontal">
                <Button x:Name="btnSave" Text="Save"/>
                <Button x:Name="btnCancel" Text="Cancel"/>

            </StackLayout>
        </StackLayout>


    </Frame>
</ContentView>

PushAsync is not supported globally on Android, please use a NavigationPage - Xamarin.Forms

$
0
0

Hi,
i use MasterDetail Page in My Main Page but when i can't use PushModalAsnyc or PushAsnyc in MainPage
when i use it i have this error :
PushAsync is not supported globally on Android, please use a NavigationPage - Xamarin.Forms

App.xaml.cs

MainPage=new MainPage();

MainPage.xaml
`

<MasterDetailPage.Master>
    <views:MenuPage />
</MasterDetailPage.Master>
<MasterDetailPage.Detail>
    <NavigationPage>

        <x:Arguments>
            <pages:TrendingPage />
        </x:Arguments>
    </NavigationPage>
</MasterDetailPage.Detail>

`

MainPage.xaml.cs

public async Task NavigateFromMenu(int id)
        {
            if (!MenuPages.ContainsKey(id))
            {
                await Navigation.PushAsync(new AboutPage());
            }
}

MenuPage.xaml.cs

        menuItems = new List<HomeMenuItem>
        {
            new HomeMenuItem {Id = MenuItemType.Home, Icon="icon_home.png",Title="صفحه اصلی" },
            new HomeMenuItem {Id = MenuItemType.Profile, Icon="icon_user.png",Title="ورود / ثبت نام" },
        };

        menu_list.ItemsSource = menuItems;

        menu_list.SelectedItem = menuItems[0];
        menu_list.ItemSelected += async (sender, e) =>
        {
            if (e.SelectedItem == null)
                return;

            var id = (int)((HomeMenuItem)e.SelectedItem).Id;
            await RootPage.NavigateFromMenu(id);
        };

how can i use pushModalAsync and pushAsync ??

How do I create N frames, based on N List elements?

$
0
0

Hello everyone!
I am working on an article based app, and I was thinking about showing them in a "stacklayout", which contains frames with the article information.
The thing is, I have 150 articles. That means, mentioning all 150 Frames in XAML file, and maybe there is a need for a change on each frame (binding wise. I don't know yet how to do this).

Do you have any idea how to make it a bit more elegant? maybe create all 150 frames on code behind?
Any advise will be great.

WindowSoftInputMode="Resize" SHELL issues

$
0
0
Hello,
I have a login screen with two entry fields for email and password with a login button.
I am using WindowSoftInputmode in android to make sure the entries are visible when the soft keyboard is displayed.
I am using The Xarin Forms Shell with bottom Navigation(tabbar). When the keyboard is displayed the bottom bar is being pushed up and displayed above the keyboard.
Any idea how I can tackle this issue and make sure my bottom navigation is not displayed above the keyboard?

Post and Get Parameter In Webview

$
0
0

Hi,

Anyone knows on how to post url with parameters to payment gateway using webview in xamarin page? And get method to process the response received from payment gateway?

Thank you.

Very slow performance when making calls to ASP.NET (ASMX) web service.

$
0
0

After migrating our Xamarin Forms project from VS 2017 (Xamarin Forms 4.2.0.848062) to VS 2019 (Xamarin Forms 4.6.0.800) during stress and performance testing we noticed significant performance degradation when downloading files from ASP.NET (ASMX) web service. This is happening for Android and iOS but the problem is especially severe for Android.
For Android project we tried to set:
HTTPClient Implementation build option to Android,
SSL/TLS Implementation build option to Native TLS 1.2+
but it didn't improve performance by much.

Our Xamarin Forms project uses platform (Android/iOS) based generated proxy to call web service.

Testing procedure:
Our Xamarin Forms app sequentially downloads 150 files ( each files size is roughly 1 MB) from ASP.NET (ASMX) web service.
The results of our testing:
Android:
App built with VS 2019 (Xamarin Forms 4.6.0.800) is 35-45% slower then app built with VS 2017 (Xamarin Forms 4.2.0.848062).
iOS:
App built with VS 2019 (Xamarin Forms 4.6.0.800) is 10-20% slower then app built with VS 2017 (Xamarin Forms 4.2.0.848062).

We tried different IIS Authentication methods (Basic, Digest, Windows) and web service binding protocols (HTTP and HTTPS) but that didn't improve performance.

This is very serious issue for us and it is important to improve performance at least back to the level of VS 2017 (Xamarin Forms 4.2.0.848062) build.

Any help or suggestions or workarounds will be greatly appreciated.

Thanks for help,

Leo

Viewing all 89864 articles
Browse latest View live