简体   繁体   中英

Xamarin Forms Button IsVisible Binding not Working on Android

I tried searching for the same error with no results so here's my question:

I have a Xamarin form project that will be deployed on Android and iOS. In one of my views i have 2 buttons that will only be visible if the user has selected a few option first. This is working just fine on iOS, but when I deploy on the Android simulator the buttons are not being displayed unless I switch orientations. Here's a sample of the code:

<Button
    Grid.Column="0"
    Grid.Row="0"
    TextColor="{StaticResource AwesomeTxtColor}"
    Text="Click Me"
    BackgroundColor="{StaticResource AwesomeBgColor}"
    IsVisible="{Binding SelectedIndex, Converter={StaticResource isGreaterOrEqualZero}}"
    Command="{Binding AwesomeCommand}" />

Again, converter is working per debugging session and bindings too. The issue is only happening for me on Android. iOS is working as expected. Xamarin Forms version: 2.3.4.267. Anyone have experienced this before or have any ideas on what might be the problem?

It turned out that it was a threading issue. Lists used to populate pickers on my view were loaded using:

await Task.Run(() => {
  //API calls to load lists
});

I changed that to:

Device.BeginInvokeOnMainThread(() => {
  //API calls to load lists
});

And now Android updates the UI. Odd but apparently those values on the lists were stuck on a different thread...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM