Home > Not CodeFluent Related :), WPF > BooleanToVisibilityConverter

BooleanToVisibilityConverter


Developing a WPF application, and you’re looking for a way to display automatically a control depending if a value is true or false?

You probably noticed by now that there are no boolean property Visible on WPF controls like there was in Windows Forms, but instead a Visibility property taking a Visibility enumeration. This then means that you’re going to have to convert your boolean value into a Visibility enumeration value.

We’ve seen in several projects that developers usually write a WPF converter so they can bind to their boolean while converting it to the proper value. That’s great and that’s the way to do it, however, did you know that the .NET Framework already provides such converter?!

Starting from the .NET 3.0, the PresentationFramework.dll, in the System.Windows.Controls namespace, provides a BooleanToVisibilityConverter which does the job, without you having to write some extra-lines of code Winking smile

Carl Anderson

  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s