简体   繁体   English

Xamarin 表单按钮 IsVisible 绑定不适用于 Android

[英]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.我有一个将部署在 Android 和 iOS 上的 Xamarin 表单项目。 In one of my views i have 2 buttons that will only be visible if the user has selected a few option first.在我的一个视图中,我有 2 个按钮,只有在用户先选择了几个选项时才会显示这些按钮。 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.这在 iOS 上工作得很好,但是当我在 Android 模拟器上部署时,除非我切换方向,否则按钮不会显示。 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.这个问题只发生在我的 Android 上。 iOS is working as expected. iOS按预期工作。 Xamarin Forms version: 2.3.4.267. Xamarin 表单版本: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.现在 Android 更新了 UI。 Odd but apparently those values on the lists were stuck on a different thread...奇怪,但显然列表中的那些值被卡在了不同的线程上......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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