Xamarin binds default value in xaml

I would like to set my visible object property to xaml by default if false. But when I open the page, it is visible, and then evaluates the binding variable, and if it is false, it becomes invisible. I want it to go through defalt, and if the binding variable is true, it becomes visible. I tried to insert a default value in my binding for the visibility property of my object. I tried FallbackValue = Hidden or Collapsed or everything else, even for TargetNullValue, but this does not work. I always get a XamlParseException.

Can anybody help me? Thank.

code (simplified):

 <Grid HorizontalOptions="FillAndExpand"
            IsVisible="{Binding Path=Info.IsVisible, Converter={StaticResource BooleanToStringConverter}, FallbackValue=Collapsed}"
+4
source share
1

IsVisible true. Binding. :

<Image x:Name="myImage" Aspect="AspectFit" WidthRequest="20" 
       HeightRequest="20" HorizontalOptions="End" VerticalOptions="End" 
       IsVisible="{Binding PropertyNameOfYourModel}" />
// Somewhere in the constructor
this.myImage.IsVisible = false;

// Here the binding is set at a later time
this.BindingContext = yourModelObject;
this.myImage.SetBinding(Image.IsVisibleProperty, "PropertyNameOfYourModel");
0

Source: https://habr.com/ru/post/1681176/


All Articles