Frame IsVisible Binding has no effect

Viewed 159

I am having an issue with my Binding on isVisible in latest .Net Maui Preview 17.3.0 Preview 2.0. Probably unrelated to the version. I am not using MVVM..here is my code:

 <Frame Background="LightBlue" IsVisible="{Binding FrameVisible}" x:Name="Frame_Test" Margin="0,10,0,0" CornerRadius="25" HeightRequest="100">

In the backend of the XAML, I have the boolean I am trying to bind to

private bool frameVisible;
        public bool FrameVisible
        {
            get
            {
                return frameVisible;
            }
            set
            {
                frameVisible = value;
                OnPropertyChanged("FrameVisible");
            }
        }

I am implementing INotifiyPropertyChanged

public event PropertyChangedEventHandler PropertyChanged;

        private void OnPropertyChanged(string propertyName)
        {
            Console.WriteLine($"[App] Property changed {propertyName}");
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

In my class constructor I am setting bindingcontext = this; What am I missing? The OnPropertyChanged triggers after changing frameVisible = false or true but I don't see any changes on GUI for the frame. The result after hovering over Xaml shows No datacontext found for binding.

2 Answers

Use Border instead of Frame. Example:

<Border Stroke="Black" StrokeThickness="2" IsVisible="{Binding FrameVisible}" x:Name="Frame_Test">
    <Border.StrokeShape>
        <RoundRectangle CornerRadius="0,0,0,0" />
    </Border.StrokeShape>
    <!-- Object you wish to wrap border around -->
</Border>
Related