tags:

views:

22

answers:

1

Hi,

What's the best way (in a WPF app, C#) of implementing control behaviour that is based around the current status/mode for the window?

For example let's say the modes might be simply OFFLINE, ONLINE for example. So when OFFLINE you want the configuration entry controls to be active, however as soon as processing starts (ONLINE) then you want these controls to be grey'ed out.

Any suggestions re pattern/approach to manage this? I'm wondering if there is a publish/subscribe approach that would be best, or just create a helper method like "SetStatus" and make all the calls to controls from here.

thanks

+3  A: 

I would bind the IsEnabled property of whatever contains your configuration entry controls to a boolean value that inspects the current status/mode.

The downside to this approach is that you will have to make a call to this property every time the Mode is changed. But this can be made easier by using properties that wrap around a member variable

//Assumes your mode enum is defined and named WindowModes
private WindowModes m_CurrentMode;
public WindowModes
{
    get { return m_CurrentMode; }
    set
    {
         m_CurrentMode = value;
         if (PropertyChanged != null)
             PropertyChanged(this, new PropertyChangedEventArgs("CanConfigure"));
    }
}

public bool CanConfigure
{
    return(WindowMode == WindowModes.Online)
}

Of course if your Mode IS boolean such as ONLINE/OFFLINE. then you could simply wrap that value the same way.

This approach of course has various scalability issues and is quite class restrictive, but I've found it useful in some scenarios.

Val