WPF: default value for converter before setting DataContext

Now I am working with WPF. My visibility visibility is tied, as here:

<Button Content="Click me!" Visibility="{Binding Path=SomePath,  Converter={StaticResource MessageCloseConverter}}"/>


It works after DataContext. But when I start the project for the first time DataContext, it is null, and visibility is visible. I want the visibility to be minimized for the first time, and after installation the DataContextconverter should work as it is now.

+4
source share
1 answer

Use property FallbackValue:

<Button Content="Click me!" Visibility="{Binding Path=SomePath,  Converter={StaticResource MessageCloseConverter}, FallbackValue=Collapsed}"/>
+6
source

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


All Articles