views:

352

answers:

2

I have a boolean global variable that is set true if an administrator is logged in and wants to amend the content of the lists and comboboxes. As a result, a button is displayed beside each combo to display a dialog box when clicked.

If I was not coding for WPF, I would probably include some sort of code similar to the following in each Window:

If gAdminEditLists=True Then btnUpdateCombo.Visibility=Visible Else btnUpdateCombo.Visibility=Collapsed

In my WPF app, I am using a style for the button that is used throughout the application and I am guessing that the best way forward is to set the Visibility of the button within the style based upon the value of the gAdminEditLists variable.

The only way I can see of doing this is to use some sort of converter within the button style that converts the gAdminEditLists value to visible or collapsed.

I'm not too sure how to proceed with this or whether this is the best approach, so any suggestions would be appreciated.

A: 

Have a look at the BooleanToVisibilityConverter class in the System.Windows.Controls namespace.

Stu Mackellar
Hi Stu, I've been using the BooleanToVisibilityConverter in other areas of the app with success but I'm not sure how to use it or a Converter WITHIN a style and based upon the value of a Global Variable.
Mitch
A: 

well your problem is that you're using a global variable isn't it?

if you had a property that implemented notification or a dependency property you would be ok. the closest thing to a global variable is a property on the app ( i assume thats where your global is )

defining dependency properties on app.xaml, however you could just use INotifyPropertyChanged.

binding to properties in app.xaml.cs

enjoy!

Aran Mulholland
Aran, thanks for pointing me in the right direction, I used your second suggestion and that worked perfectly!
Mitch