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

Xamarin.Forms bug? System.ObjectDisposedException: Cannot access a disposed object

$
0
0

Hi,

My Android Xamarin.Forms application uses a Navigation stack to display various views, I often have a list on a screen (A) that once a cell is clicked I push onto the stack a new screen (B), the user completes some form fields and then clicks a button to save. Once they click the 'save' button a task is created on the thread pool to asynchronously perform some work (no async/await and no dependency on any UI) and the view is popped back to screen (A).

Once the task is completed, it fires a simple event using the PubSub library, on the UI thread, so screen (A) has the opportunity to refresh from the local database and it does.

The problem is that when I go to drag the updated list on screen (A), the app crashes with an ObjectDisposedException intermittently (like 1 in 50 times)...

System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'Android.Views.GestureDetector'.
  at Java.Interop.JniPeerMembers.AssertSelf (Java.Interop.IJavaPeerable self) [0x00030] in /Users/builder/data/lanes/3819/c1d1c79c/source/Java.Interop/src/Java.Interop/Java.Interop/JniPeerMembers.cs:153
  at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeVirtualBooleanMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x00002] in /Users/builder/data/lanes/3819/c1d1c79c/source/Java.Interop/src/Java.Interop/Java.Interop/JniPeerMembers.JniInstanceMethods_Invoke.cs:57
  at Android.Views.GestureDetector.OnTouchEvent (Android.Views.MotionEvent ev) [0x0002c] in /Users/builder/data/lanes/3819/c1d1c79c/source/monodroid/src/Mono.Android/platforms/android-23/src/generated/Android.Views.GestureDetector.cs:1546
  at Xamarin.Forms.Platform.Android.VisualElementRenderer`1[TElement].Android.Views.View.IOnTouchListener.OnTouch (Android.Views.View v, Android.Views.MotionEvent e) [0x0003f] in C:\BuildAgent2\work\aad494dc9bc9783\Xamarin.Forms.Platform.Android\VisualElementRenderer.cs:101
  at Android.Views.View+IOnTouchListenerInvoker.n_OnTouch_Landroid_view_View_Landroid_view_MotionEvent_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_v, System.IntPtr native_e) [0x00019] in /Users/builder/data/lanes/3819/c1d1c79c/source/monodroid/src/Mono.Android/platforms/android-23/src/generated/Android.Views.View.cs:3558
  at at (wrapper dynamic-method) System.Object:4eaabbb9-8c1c-4ea1-b505-44c325bbb1ab (intptr,intptr,intptr,intptr)

I'm not sure why it says that I cannot access a disposed object, I'm interacting with a list with a gesture detector, it's on-screen, so it's not disposed.

Is this a bug in Xamarin.Forms?

On a similar note, if I modify an MVVP property that notifies listeners that a property has changed (I always check it's on the UI thread first), then if that's bound to a Xamarin.Forms list but it's not currently on-screen, presumably Xamarin.Forms will not barf ? After-All it's just off-screen and should still bind okay?


CarouselView; databinding handling specific data types

$
0
0

I currently have a carouselView whereby I am managing different parts of the content in the view via NVVM. I am trying to bind Image.SourceProperty to an image that is displayed in the carousel view. I have a model in which I have an ImageSource datatype. Saving this model to the SQL lite database causes a crash as Image.SourceProperty is not supported (nor should it be).

Hence my approach of putting Image.SourceProperty in the model which is saved to the database is clearly wrong. My question is therefore how can I handle this situation? Should I create an alternative class within my viewmodel and put Image.SourceProperty variable there and associate it with my public ObservableCollection Cars models? What is the standard best practice for handling such situations?

**Models.cs**

    public class Car
    {
        [SQLite.PrimaryKey, SQLite.AutoIncrement, SQLite.Column("_id")]
        public int Id { get; set; }

        //  This will cause an exception saving this model to SQL lite database
        //  I need to put this somewhere else, likely within CarViewModel.cs 
        public ImageSource CarImageSource { get; set; }
    }


**CarPage.xaml.cs**


    carCarouselView.ItemsSource = (BindingContext as CarViewModel).Cars;
    carCarouselView.SetBinding(ItemsView.ItemsSourceProperty, "Cars");

    carCarouselView.ItemTemplate = new DataTemplate(() =>
    {
        StackLayout rootStackLayout = new StackLayout
        {
            Children = 
            { 
                var carImage = new Image { };
                //  This is what i'm trying to do
                carImage.SetBinding(Image.SourceProperty, "CarImageSource");
            }
        };

        return rootStackLayout;
    });

**CarViewModel.cs**

    public class CarViewModel 
    {
        readonly IList<Car> source;
        public ObservableCollection<Car> Cars { get; private set; }   
    //  Shall I create an additional class here?
    }

Best Practice / Publish Android Apps in a company

$
0
0

I develop apps for Android that only need to be distributed in one company. I'm still a beginner and wonder what is the best way to distribute my apps to the devices. Currently this is still done via USB. Does it make sense to use the Google Store or are there other tools with which I can roll out specific updates. The user himself should not be allowed to do this. I find very little information about this. Generally the topic "distribution" is underrepresented in my opinion.

All Apps are using WiFi and the internal Network only.

ITMS-90809: Deprecated API Usage - UIWebView

$
0
0

Hi,
I'm trying to submit a Xamarin Forms Shell app to the Apple Store but it is always rejected because of this:

TMS-90809: Deprecated API Usage - New apps that use UIWebView are no longer accepted. Instead, use WKWebView for improved security and reliability. Learn more (https://developer.apple.com/documentation/uikit/uiwebview).

I have already follow the workaround discuss here
but it doesn't works.

I don't use UIWebView in my application
no UIWebView

My iOS build configuration is the follow:
ios configuration

I'm using XF 4.5.0.356.

What did I do wrong?
How can I solve this?

Focus on Next Entry after max length of 1

$
0
0

I have created dynamic 20 entries and want to focus on next entry after user enter a digit and max length of entry is 1. The focus should be automatically move on next entry.I am sharing my code.Thanks in advance for help.

//model

 public  class CrossingUIModel
    {
    public int Id { get; set; }
    public string FieldValue { get; set; }      
   }

//on change property

private ObservableCollection<CrossingUIModel> bindCrossingUIModel;

    public ObservableCollection<CrossingUIModel> BindCrossingUIModel
  {
    get { return bindCrossingUIModel; }
    set
    {
            bindCrossingUIModel = value;
        OnPropertyChanged(nameof(BindCrossingUIModel));
    }
  }

//creating ui

  public void CreateUI()
    {
        UserDialogs.Instance.ShowLoading();

        BindCrossingUIModel = new ObservableCollection<CrossingUIModel>();

        for (int i = 1; i < 21; i++)
        {
            CrossingUIModel model = new CrossingUIModel();
            model.Id = i;
            BindCrossingUIModel.Add(model);
        }

        UserDialogs.Instance.HideLoading();

    }

//xml file

           <CollectionView x:Name="CrossingView" ItemsSource="{Binding BindCrossingUIModel, Mode=TwoWay}" SelectionMode="Multiple">
                        <CollectionView.ItemsLayout>
                        <GridItemsLayout Orientation="Vertical"  Span="10" />
                    </CollectionView.ItemsLayout>

                    <CollectionView.ItemTemplate>
                        <DataTemplate>
                            <StackLayout HorizontalOptions="FillAndExpand">
                                <Entry x:Name="Fields" Text="{Binding FieldValue, Mode=TwoWay}" 
                                       ReturnType="Next" MaxLength="1" Keyboard="Numeric" 
                                       TextChanged="Fields_TextChanged" ></Entry>
                            </StackLayout>
                        </DataTemplate>
                    </CollectionView.ItemTemplate>
                </CollectionView>

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?

Xamarin form - Firebase notification with image

$
0
0

i want to send notification from firebase console with image, i have successfully implement in my xamarin form i can get device token and can send notification to device from firebase console, but the problem is that i want to send notification with image and i dont know how i can do that, as in firebase console there is no option to select image or write url, so it must be something from xamarin form where we recieve notification. Please check the image below how i want to recieve notification.

notification with image

Not able to reference Xamarin.Essentials in .Android project

$
0
0

I have added Xamarin.Essentials to all the projects. But when I try to put in the setup code in ManiActivity's OnCreate event, Xamarin.Essentials is not referenced. It is not in the References too. Unable to add it separately. The NuGet explorer shows that it is installed for Android project too.

My Android project is targeted to V8.1 and Android Support Libraries are of V27.0.2.1 as required by the documentation.

What am I missing?


Problem with ImageButton when changing the Source-Image

$
0
0

Hi,

I'm using the new ImageButton to implement a ToggleButton which switches between a "Locked" and "Unlocked" state.
The "Source"-Property is bound to a bool-Property in the ViewModel and using a ValueConverter to set the name of the according image:

            <ImageButton                    
                Command="{Binding ToggleLockStateCommand}"
                BackgroundColor="Transparent"
                Source="{Binding Locked, Converter={StaticResource cnvLockStateToImage}}">

Changing the images works as expected but after changing the image is not correctly sized, it randomly switches between "very small" and the original size.

I already verified that the ImageButton doesn't change its size when the Source is changed (which is expected as the two images are of the same size).

Anybody has an idea how to fix this (or maybe it's a bug?) My target-platform is Android.

-Michael

How to clear ListView

$
0
0

Hi,

I have latest version of xamarin forms installed 2.3.4.247. What I want is to clear my listview and repopulate it. Kind of like refresh.

But currently, the list view stays same once loaded.

Change cursor color in entry

$
0
0

Hi guys,

I want to change the cursor color in an entry to white, how can I do this? I tried a lot..;(

ScrollView and image

$
0
0

Hello, I'm working with Xamarin.Forms 4.7. I'm trying to display a large image (large width and tight height) and I would like to be able to scroll it horizontally with a custom height.

I have the basic following code :

What I have now is an image that fill the parent horizontally (I think this is due to AspectFit option by default). The height request seems to do nothing. I have tried to use AspectFill, it resized my image to fit vertically with the scollView, but I can't scroll anymore.

Does anyone have a solution to do this ?

Thanks for any help.

Mike.

cannot show urhosharp surface multiple times

$
0
0

When the user open the view, navigate backwards and open the view a second time, the app crashes.
Any idea how to go around this issue?
Idealy, I would like to call:

skyUrho = await urhoSurface.Show<SkyUrho>(urhoApp);

only once in the constructor but that is not possible as it is an async call.

This is the code behind of the view:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Xamarin.Forms;
using Xamarin.Forms.Xaml;

using AlmicantaratXF.ViewModels;
using AlmicantaratXF.Model;

namespace AlmicantaratXF.Views
{
    [XamlCompilation(XamlCompilationOptions.Compile)]
    public partial class SkyUrhoSurface : ContentPage
    {
        private Sight currentSight;
        private SkyUrho skyUrho;
        private INavigation navigation;
        private Urho.ApplicationOptions urhoApp;
        public SkyUrhoSurface()
        {
            InitializeComponent();
            this.currentSight = null;
            urhoApp = new Urho.ApplicationOptions(assetsFolder: "Data");
        }
        public SkyUrhoSurface(Sight currentSight, INavigation navigation)
        {
            InitializeComponent();
            this.currentSight = currentSight;
            this.navigation = navigation;
            urhoApp = new Urho.ApplicationOptions(assetsFolder: "Data");
        }
        protected override async void OnAppearing()
        {
            base.OnAppearing();
            skyUrho = await urhoSurface.Show<SkyUrho>(urhoApp);
          //SkyUrho skyUrho = new SkyUrho(new Urho.ApplicationOptions(assetsFolder: "Data"));
            skyUrho.PageVisible = true;
            skyUrho.StarSelection = (currentSight != null);
            buttonShootThisBody.BindingContext = skyUrho;
            labelLat.BindingContext = skyUrho;
            labelLon.BindingContext = skyUrho;
            labelAltitude.BindingContext = skyUrho;
            labelAzimuth.BindingContext = skyUrho;
            labelBodysName.BindingContext = skyUrho;
            labelBodysDirection.BindingContext = skyUrho;
            labelGPSStatus.BindingContext = skyUrho;
            //activityIndicator.BindingContext = skyUrho;
            activityIndicator.IsVisible = false;
            activityIndicator.IsRunning = false;
        }
        protected override async void OnDisappearing()
        {
            base.OnDisappearing();
            if (skyUrho != null)
                skyUrho.PageVisible = false;
        }
        void OnCheckBoxNamesChanged(object sender, CheckedChangedEventArgs e)
            {
                if(skyUrho!=null)
                    skyUrho.Names = e.Value;
            }
        void OnButtonShootThisBodyClicked(object sender, EventArgs args)
        {
            if(skyUrho!=null)
                if(skyUrho.SelectedStar!=null)
                    this.currentSight.StarID = (int)skyUrho.SelectedStar;
            navigation.PopAsync();
        }
    }
}

cannot delete app data, where is Environment.SpecialFolder.LocalApplicationData stored?

$
0
0

Something very strange,
I use sqlite-pcl-net v1.7.302-beta
I store datas in a sqlite database.
I debug my app on a android device.

I cannot delete the datas:

  • If I delete an item, when I start the app again, the item comes back.
  • If I delete the datas of the app, the datas come back.
  • If I delete the datas and unistall the app, the datas comes back?!!

This is my App.xaml.cs code:

        public static PositionsSightsDatabase PositionsSightsDB
        {
            get
            {
                if (positionsSightsDatabase == null)
                {
                    positionsSightsDatabase = new PositionsSightsDatabase(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "PositionsSightsSQLite.db3"));
                }
#if DEBUG
                System.Diagnostics.Debug.WriteLine("db3 folder: " +  Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData));
#endif

                return positionsSightsDatabase;
            }
        }

The result is:
'/data/user/0/almicantarat.almicantarat/files/.local/share

When I browse my device, I don't find .local/share
Where are the datas stored? on my PC by VS?
Why is it impossible to delete the whole database?

Xamarin Forms Push Notifications

$
0
0

Hello,

am implementing push notifications to a Xamarin.Forms app. I included this plugin - https://github.com/CrossGeeks/FirebasePushNotificationPlugin. It works great, the only thing that I am missing is getting push notifications when the app is closed (killed).

Started playing with the sample the plugin authors provide (https://github.com/CrossGeeks/FirebasePushNotificationPlugin/tree/master/samples), just needed to add Xamarin.GooglePlayServices.Base nuget package, the rest is almost untouched. I set up the project in Firebase Console and now I can send notifications from Postman, which looks good:

when app is in foreground then the
CrossFirebasePushNotification.Current.OnNotificationReceived
event is properly triggered

when app is backgrounded then the notification is displayed, jingle is played and when I click it, the
CrossFirebasePushNotification.Current.OnNotificationOpened
event is triggered.

So far so good.

But how to show notification when the app is killed? I supposed it should be done by operating system when notification arrives? But obviously I am wrong or I am missing something. If i send a notification from Postman and the app is closed then nothing happens, no notification is displayed and no event is triggered.

There is also following event handler in MainApplication.cs class that looks promissing but it is also triggered only when app is backgrounded.

  //Handle notification when app is closed here
            CrossFirebasePushNotification.Current.OnNotificationReceived += (s, p) =>
            {
                System.Diagnostics.Debug.WriteLine("NOTIFICATION RECEIVED", p.Data);
            };

Any ideas how to make this work?

thanks

Jiri


Shell custom renderer how create bottom tabbar shadow?

$
0
0

Android and ios Shell custom renderer how create bottom tabbar shadow like as same as top navigation of shadow

Working Xamarin.Forms Mac Sample

$
0
0

I can't get XF working on Mac. Can someone please point me to a working sample? Please don't point me to any of the documentation on how to create one. I am looking for a sample that I can download that already works.

The walkthrough doesn't work. I tried working through this:
https://docs.microsoft.com/en-us/xamarin/xamarin-forms/platform/other/mac

Firstly, when the NuGet package is added, it adds these references which I believe are incorrect because they are not Mac specific. Obviously, these .NET standard assemblies won't have the necessary macOS specific code:

The result is this:

So, I deleted the references and manually pointed the project to what should be the correct macOS specific assemblies. These are in the Xamarin.Mac folder and should have the macOS platform specfic code:

But, I get the exact same problem. The Xamarin.Forms.Platform.MacOS namespace simply doesn't exist.

I've tried many versions of the NuGet package. From 4.5, 4.6, to 4.7. They all have the same problem.

Profile images

$
0
0

Good night guys, I have a chat application where each user has their image. The aplicitvo works offline and the users' images are in the local bank (SQLite) in BASE64.

To display these images in the chat list and other elements what is the best way?
1) Load the images into memory by converting BASE64 to an image.
2) Generate the images physically in an APP folder and use the physical path.
3) Another suggestion.

If anyone has been through this scenario, please give me a light.

Constructor injection in NavigationPage used in TabbedPage

$
0
0

I have a custom NavigationPage:

namespace Common.Views
{
    public class NavigationPage : Xamarin.Forms.NavigationPage
    {
        public NavigationPage(IConfiguration configuration)
        {
            BarBackgroundColor = Color.FromRgb(configuration.Colors.PrimaryColor.R, configuration.Colors.PrimaryColor.G, configuration.Colors.PrimaryColor.B);
            BarTextColor = Color.FromRgb(configuration.Colors.SecondaryColor.R, configuration.Colors.SecondaryColor.G, configuration.Colors.SecondaryColor.B);
        }
    }
}

I want to use it in the TabbedPage:

<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
            xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
            xmlns:views="clr-namespace:My.Views"
            xmlns:commonViews="clr-namespace:Common.Views;assembly=Common"
            x:Class="My.Views.TabbedMainPage">
    <TabbedPage.Children>

        <commonViews:NavigationPage IconImageSource="Home" Title="Home">
            <x:Arguments>
                <views:HomePage />
            </x:Arguments>
        </commonViews:NavigationPage>

This gives the error:
Type 'NavigationPage' is not usable as an object element because it is not public or does not define a public parameterless constructor or a type converter.

How can I fix this error and maintain constructor injection?

Xamarin.UITest - how to assert if button is disabled

$
0
0

Hi All,
is there a way how to assert if button is disabled? If I query for a button I can see property called Enabled, but that is always true, even if button is not clickable, so I can not use that.

From our devs I found out that they are using property IsActive to determine if button is clickable or not.

But I don't see such property when using REPL. How do I find out if button is clickable or not?

Thank you.

Viewing all 79144 articles
Browse latest View live


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