tags:

views:

35

answers:

2

I'm fairly new to WPF and I have this scenario:

I have an application that contains an area where different sets of controls should be displayed at different time(different application states).

I'm wondering what is the approach in WPF?

In winforms I would make controls visible/invisible at runtime. If there were too many controls I would group them on Panels/UserControls and show/hide those.

My gut tells me there is a better way in WPF.

A: 

The Visibility property describes your old winforms habits perfectly.

You'll also want to look into Visual States. This will allow you to hide/show multiple controls and even change other properties (i.e. enable state, font color).

Ragepotato
+1  A: 

There are lots of options for doing this in WPF. In addition to hiding and showing individual or groups of controls by setting Visibility, you could use different DataTemplates to contain the set of controls for each state and switch between those. All you need is a ContentControl on which you can set the ContentTemplate. The ContentTemplate value can then be switched to different DataTemplates using a Trigger, a Binding, from code, or by using ContentTemplateSelector to choose a template.

John Bowen
Would be datatemplates still useful if I had different models and diferent logic behind changing areas?
Kugel
Definitely. Switching out the class used for your Binding source can make it even more useful. For example, if you have two different ViewModel classes to drive two UI states you can define two DataTemplates as Resources with just DataTypes and no x:Keys. You can then just assign either of the ViewModel objects to a ContentControl's Content property and it will automatically pick up the right template.
John Bowen