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

Unhandled exception with button with image on Android

$
0
0

I am having runtime error "Unhandleled Exception" on Android with the following code while it is running okay on WP.

` #region Org

        var lblOrg = new Label
        {
            Text = "Organisation",
            MinimumWidthRequest = 60,
            HorizontalOptions = LayoutOptions.Start

        };


        var pickOrg = new Picker() { HorizontalOptions = LayoutOptions.FillAndExpand };

        pickOrg.SelectedIndexChanged += (sender, args) =>
        {
            if (pickOrg.SelectedIndex != -1)
            {
              //logic here
            }
        };


        var btnOrgRefresh = new Button() { Font = Font.SystemFontOfSize(NamedSize.Micro), WidthRequest = 80, HeightRequest = 40 };
        btnOrgRefresh.SetBinding(Label.TextProperty, "LabelOfOrgs");
        var btnOrgImage = Device.OnPlatform(iOS: ImageSource.FromFile("Images/An_image.jpg"),
        Android: ImageSource.FromFile("refresh.jpg"),
        WinPhone: ImageSource.FromFile("Images/refresh.jpg"));
        btnOrgRefresh.Image = ((Xamarin.Forms.FileImageSource)(btnOrgImage)).File;

        var layoutOrgs = new StackLayout() { Orientation = StackOrientation.Horizontal };
        layoutOrgs.Children.Add(lblOrg);
        layoutOrgs.Children.Add(pickOrg);
        layoutOrgs.Children.Add(btnOrgRefresh);//PROBLEM LINE

        btnOrgRefresh.Clicked += btnOrgRefresh_Clicked;

        #endregion`

Later I add this in page content:

Content= new ScrollView()
            {
                Content =
                    new StackLayout
                    {
                        HorizontalOptions = LayoutOptions.FillAndExpand,
                        Children =
                        {
                            layoutOrgs,

Can anybody tell me why the PROBLEM LINE producing error on Android but not on WP?


Viewing all articles
Browse latest Browse all 58056

Trending Articles



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