Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF: Converter default value before DataContext set

Tags:

c#

wpf

Now I am working with WPF. My Controls visibility binded like in here:

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


This works after DataContext is setted. But when I run project first time DataContext is null and Visibility is Visible.I want set visibility collapsed first time and after setting DataContext converter should work like now.

like image 352
Jamaxack Avatar asked Mar 18 '23 12:03

Jamaxack


1 Answers

Use the FallbackValue property:

<Button Content="Click me!" Visibility="{Binding Path=SomePath,  Converter={StaticResource MessageCloseConverter}, FallbackValue=Collapsed}"/>
like image 58
Tim Eeckhaut Avatar answered Mar 31 '23 11:03

Tim Eeckhaut