Thursday, May 7, 2009

WPF: boolean to visibility converter

Hi Folks,

recently I had the pleasure to remove home-brewn converters named VisibilityOfBoolean and VisibilityOfChecked and started using System.Windows.Controls.BooleanToVisibilityConverter instead.

Example of usage in XAML, experienced reader fills in the details:

<BooleanToVisibilityConverter key="VisibilityOfBool" />

and later:

Visibility="{Binding ElementName=checkboxVisible, Path=IsChecked, Converter={StaticResource VisibilityOfBool}}"

Easy as a pie. I only wish there was an equally easy way to invert a boolean value!