Bug 60530 - Button inside Content Page with IsVisible binding not working only on Android
Summary: Button inside Content Page with IsVisible binding not working only on Android
Status: RESOLVED ANSWERED
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 2.4.0
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2017-11-06 15:22 UTC by Osvaldo Rodriguez Torres
Modified: 2017-11-07 17:53 UTC (History)
3 users (show)

Tags: android forms binding isvisible
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED ANSWERED

Description Osvaldo Rodriguez Torres 2017-11-06 15:22:15 UTC
Hello, 

This is my first time submitting an issue here so I hope I provide all the necessary information. Here it goes:

I have a Xamarin Forms project which is set to be deployed on Android and iOS. I am primarily using Visual Studio for MAC although sometimes I use Visual Studio 2017 for PC without a problem. The problem is with one of my Content Pages on which I have a series of Pickers. On that same page I have 3 buttons (Option 1, Reset, Option2 for example). The reset button is always visible however, the other 2 will only be visible once the user have a selection on all Pickers (that's a requirement). This is working fine on iOS (Simulator) however when I test on Android it won't work. At the beginning I was able to uninstall the app from the Android emulator and then install it again and it will work the first time. I do not remember on which Xamarin Forms version I started developing, right now I'm using 2.4.0.38779 and the only way I'm able to see the buttons is by switching orientations on Android. This somehow "updates" the view and the buttons will appear. Given all this I believe this could be a Xamarin bug.

This is my XAML code:

<?xml version="1.0" encoding="UTF-8"?>
<ContentPage 
        xmlns="http://xamarin.com/schemas/2014/forms" 
        xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
        x:Class="AwesomeApp.Views.FiltersView" 
        xmlns:converters="clr-namespace:AwesomeApp.Converters;assembly=AweomeApp" 
        NavigationPage.HasBackButton="False" 
        NavigationPage.Title="Awesome App">
    <ContentPage.Resources>
        <ResourceDictionary>
            <converters:IsGreaterThanConverter x:Key="isGreaterThanZero" />
            <converters:IsGreaterOrEqualThanConverter x:Key="isGreaterOrEqualZero" />
        </ResourceDictionary>
    </ContentPage.Resources>
    <ContentPage.Padding>
        <OnPlatform x:TypeArguments="Thickness" iOS="10, 10, 10, 10" Android="20, 20, 20, 20" WinPhone="20, 20, 20, 20" />
    </ContentPage.Padding>
    <ContentPage.Content>
        <StackLayout
            Spacing="5">
            <Label Text="{Binding PageTitle}" Font="Large" TextColor="{StaticResource awesomeBlue}" FontAttributes="Bold" />
            <Grid x:Name="mainGrid" HorizontalOptions="CenterAndExpand" VerticalOptions="FillAndExpand" RowSpacing="5">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="2*" />
                    <RowDefinition Height="2*" />
                    <RowDefinition Height="2*" />
                    <RowDefinition Height="2*" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="2*" />
                </Grid.RowDefinitions>
                <Label 
                    Grid.Row="0" 
                    Grid.ColumnSpan="6" 
                    Text="Set your filters" 
                    HorizontalOptions="CenterAndExpand" 
                    FontSize="{StaticResource bigFontSize}" />
                <Label 
                    Grid.Row="1" 
                    Grid.Column="0" 
                    Grid.ColumnSpan="3" 
                    Text="Picker 1" 
                    HorizontalOptions="StartAndExpand" 
                    VerticalOptions="Center" 
                    FontSize="{StaticResource mediumFontSize}" />
                <Label 
                    Grid.Row="2" 
                    Grid.Column="0" 
                    Grid.ColumnSpan="3"  
                    Text="Picker 2" 
                    HorizontalOptions="StartAndExpand" 
                    VerticalOptions="Center" 
                    FontSize="{StaticResource mediumFontSize}" />
                <Label 
                    Grid.Row="3" 
                    Grid.Column="0" 
                    Grid.ColumnSpan="3"  
                    Text="Picker 3" 
                    HorizontalOptions="StartAndExpand" 
                    VerticalOptions="Center" 
                    FontSize="{StaticResource mediumFontSize}" />
                <Label 
                    Grid.Row="4" 
                    Grid.Column="0" 
                    Grid.ColumnSpan="3"  
                    Text="Picker 4" 
                    HorizontalOptions="StartAndExpand" 
                    VerticalOptions="Center" 
                    FontSize="{StaticResource mediumFontSize}" />
                <Picker 
                    Grid.Row="1" 
                    Grid.Column="3" 
                    Grid.ColumnSpan="3"  
                    x:Name="FirstPicker" 
                    HorizontalOptions="FillAndExpand" 
                    ItemsSource="{Binding LisOne}" 
                    SelectedIndex="{Binding SelectedListOneIndex}" 
                    ItemDisplayBinding="{Binding Text}">
                </Picker>
                <Picker 
                    Grid.Row="2" 
                    Grid.Column="3" 
                    Grid.ColumnSpan="3"  
                    x:Name="ListTwoPicker" 
                    HorizontalOptions="FillAndExpand" 
                    IsEnabled="{Binding ListTwo.Count, Converter={StaticResource isGreaterThanZero}}" 
                    temsSource="{Binding ListTwo}" 
                    SelectedIndex="{Binding SelectedListTwoIndex}" 
                    ItemDisplayBinding="{Binding Text}">
                </Picker>
                <Picker 
                    Grid.Row="3" 
                    Grid.Column="3" 
                    Grid.ColumnSpan="3"  
                    x:Name="ThirdPicker" 
                    HorizontalOptions="FillAndExpand" 
                    IsEnabled="{Binding ListThree.Count, Converter={StaticResource isGreaterThanZero}}" 
                    ItemsSource="{Binding ListThree}" 
                    SelectedIndex="{Binding SelectedListThreeIndex}" ItemDisplayBinding="{Binding DDL_Text}">
                </Picker>
                <Picker 
                    Grid.Row="4" 
                    Grid.Column="3" 
                    Grid.ColumnSpan="3"  
                    x:Name="FourthPicker" 
                    HorizontalOptions="FillAndExpand" 
                    IsEnabled="{Binding ListFour.Count, Converter={StaticResource isGreaterThanZero}}" 
                    ItemsSource="{Binding ListFour}" 
                    SelectedIndex="{Binding SelectedListFourIndex}" 
                    ItemDisplayBinding="{Binding DDL_Text}">
                </Picker>
                <Button 
                    Grid.Column="0" 
                    x:Name="optionOneButton"
                    Grid.Row="5" 
                    Grid.ColumnSpan="2"
                    TextColor="{StaticResource awesomeWhite}" 
                    Text="Option One" 
                    BackgroundColor="{StaticResource awesomeBlue}" 
                    IsVisible="{Binding SelectedListFourIndex, Converter={StaticResource isGreaterOrEqualZero}}" 
                    Command="{Binding GetOptionOneDataCommand}" />
                <Button Grid.Column="2" Grid.Row="5" Grid.ColumnSpan="2" TextColor="{StaticResource awesomeWhite}" Text="Reset" BackgroundColor="{StaticResource awesomeOrange}" Command="{Binding ResetFiltersCommand}" />
                <Button 
                    x:Name="optionTwoBtn"
                    Grid.Column="4" 
                    Grid.Row="5" 
                    Grid.ColumnSpan="2"
                    TextColor="{StaticResource awesomeWhite}" 
                    Text="Option Two" 
                    BackgroundColor="{StaticResource awesomeBlue}" 
                    IsVisible="{Binding SelectedListFourIndex, Converter={StaticResource isGreaterOrEqualZero}}" 
                    Command="{Binding GetOptionTwoDataCommand}" />
                <ActivityIndicator x:Name="Indicator" Grid.Column="2" Grid.Row="6" Grid.ColumnSpan="2" HeightRequest="{StaticResource mediumFontSize}" WidthRequest="{StaticResource mediumFontSize}" Color="{StaticResource awesomeBlue}" HorizontalOptions="Center" VerticalOptions="Center" IsVisible="{Binding IsBusy}" IsRunning="{Binding IsBusy}" />
            </Grid>
        </StackLayout>
    </ContentPage.Content>
</ContentPage>


I've changed some names since this is for a client but essentially every (bindings, commands, etc) is working fine on iOS. The issues is only happening on Android.

Thanks for any help.
Comment 1 Paul DiPietro [MSFT] 2017-11-06 15:31:19 UTC
Can you please upload this as a reproduction rather than a snipped so we fuller definitions for bindings? Is this a newly encountered issue since upgrading? What version of Android and which devices (if any) are exhibiting the behavior?
Comment 2 Osvaldo Rodriguez Torres 2017-11-06 15:41:35 UTC
Hello Paul, 

So far happening on a Samsung Galaxy J7 and on the Android simulator "qemu-system-i386" as it appears on my Mac. I am new here and i don't fully understand what you mean by "reproduction rather than a snipped". I am not allowed to put all my code since this is for a client but as you can see in my description this code, bindings, and everything is working fine for iOS. When i execute my code on Android is when the buttons are not being displayed. Not sure if a screenshot might help but i am pretty sure that binding is not the problem. Buttons should be displayed when "SelectedListFourIndex" is equal or greater than 0. Again, this is working when i deploy on iOS thus is the rest of the app. BTW i tried this using a Label instead of a button. I also tried using IsEnable instead of IsVisible but it seems that in Android those properties are not being "updated" properly when there's a change.

Please guide me through on how i can facilitate the information you need.
Comment 3 Osvaldo Rodriguez Torres 2017-11-06 15:42:50 UTC
Also, when i switch orientations the buttons appear. I think this is important.
Comment 4 Paul DiPietro [MSFT] 2017-11-06 16:04:00 UTC
What I mean is that when you have a bunch of code pasted as above (I meant to type "snippet" rather than "snipped"), there are bindings and commands and such it is reliant on in order to function which are not provided, which makes for more time-consuming guesswork on our end. 

The easiest way for us to investigate these issues is when a reporter is able to provide a runnable project removes all unnecessary code and only uses the bare minimum needed to show the problematic behavior. Cleaning the build and deleting bin/obj and package folders reduces the size for uploading it here as a zipped attachment. Informing us of devices or simulators/sim versions that work and do not work is also of great help for narrowing down issues.
Comment 5 Osvaldo Rodriguez Torres 2017-11-07 15:07:54 UTC
Hello Paul,

I understand. It seems that it wasn't the binding but a threading issue. I was "loading" the lists on an async function using Task,Run()... changing that to Device.BeginInvokeOnMainThread() solved my problem.

Thanks a lot for your help.
Comment 6 Paul DiPietro [MSFT] 2017-11-07 17:53:22 UTC
Thank you for the update.