Forum Xamarin.Forms

ContentView temporarily visible when IsVisible=false

Using Xamarin.Forms 4.4

I have a ContentView inside a ContentPage in order to show some info when needed, like in XAML code below:

<AbsoluteLayout>
    <Grid AbsoluteLayout.LayoutBounds="0, 0, 1, 1" 
          AbsoluteLayout.LayoutFlags="All">
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <Label Grid.Row="0"
               Text="Test"/>
    </Grid>

    <ContentView AbsoluteLayout.LayoutBounds="0, 0, 1, 1"
                 AbsoluteLayout.LayoutFlags="All"
                 IsVisible="{Binding IsContentViewVisible}"
                 BackgroundColor="{StaticResource OverlayColor}">
        <Label Text="In content view"/>
    </ContentView>
</AbsoluteLayout>

The IsVisible property of the ContentView is bound to a property which initially is set to false.
Sometimes when I navigate to that ContentPage, the ContentView is visible for a split second and then returns to the state that it should (IsVisible=false)

I’m running the app on an iPad. I have different views for Portrait and Landscape but the main structure of the view remains the same.
When I turn the iPad from portrait to Landscape and vise versa, them the ContentView is also visible for a split second and then returns to the state that it should (IsVisible=false)
The property in my ViewModel doesn’t change from false to true at any given time

Is there a solution to this problem? Am I doing it wrongly? Is there another way to handle the visibility of the ContentView?

Best Answer

Answers

  • JoeMankeJoeManke USMember ✭✭✭✭✭

    When are you setting the BindingContext of the view/page relative to the InitializeComponent() method?

  • DimitrisMylonasDimitrisMylonas USMember ✭✭

    I'm using Prism so the the setting of the BindingContext is handled by Prism

  • DimitrisMylonasDimitrisMylonas USMember ✭✭

    @LandLu

    First of all, your suggestion worked for me. I have the following code for the property that controls the visibility and I thought that since the _isContentViewVisible is set to false then I wouldn't have an issue.

    public bool IsContentViewVisible
    {
        get => _isContentViewVisible;
        set => SetProperty(ref _isContentViewVisible, value);
    }
    
    private bool _isContentViewVisible = false;
    

    So I wasn't explicitly setting the IsContentViewVisible to false. Seems that setting this property explicitly to false in the constructor, solved the issue.

    Thanks

Sign In or Register to comment.