Binding does not work for CLR objects. It only works for Dependency Properties. Hence, I would turn WindowXStyle into a read-only dependency property:
using System;
using System.ComponentModel;
using System.Windows;
namespace MyNamespace
{
public enum Phases { Phase1, Phase2, Phase3 }
public class UIStateModel : DependencyObject
{
static UIStateModel()
{
CurrentStateProperty = DependencyProperty.Register("CurrentState", typeof(Phases), typeof(UIStateModel),
new FrameworkPropertyMetadata
{
PropertyChangedCallback = new PropertyChangedCallback(OnCurrentStateChanged)
});
Window1VisibilityPropertyKey = DependencyProperty.RegisterReadOnly("Window1Visiblity", typeof(Visibility), typeof(UIStateModel),
new PropertyMetadata());
Window1VisibilityProperty = Window1VisibilityPropertyKey.DependencyProperty;
Window2VisibilityPropertyKey = DependencyProperty.RegisterReadOnly("Window2Visiblity", typeof(Visibility), typeof(UIStateModel),
new PropertyMetadata());
Window2VisibilityProperty = Window2VisibilityPropertyKey.DependencyProperty;
}
public Phases CurrentState
{
get { return (Phases)GetValue(CurrentStateProperty); }
set { SetValue(CurrentStateProperty, value); }
}
public static DependencyProperty CurrentStateProperty;
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public Visibility Window1Visibility
{
get { return (Visibility)GetValue(Window1VisibilityProperty); }
protected set { SetValue(Window1VisibilityPropertyKey, value); }
}
public static readonly DependencyProperty Window1VisibilityProperty;
private static readonly DependencyPropertyKey Window1VisibilityPropertyKey;
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public Visibility Window2Visibility
{
get { return (Visibility)GetValue(Window2VisibilityProperty); }
protected set { SetValue(Window2VisibilityPropertyKey, value); }
}
public static readonly DependencyProperty Window2VisibilityProperty;
private static readonly DependencyPropertyKey Window2VisibilityPropertyKey;
public Visibility Window1Visible // Databound to Window1.Visibility
{
get
{
if (this.CurrentState == Phases.Phase1) return Visibility.Visible;
else return Visibility.Hidden;
}
}
public Visibility Window2Visible // Databound to Window2.Visibility
{
get
{
if (this.CurrentState == Phases.Phase2) return Visibility.Visible;
else return Visibility.Hidden;
}
}
private static void OnCurrentPageChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
{
UIStateModel element = (UIStateModel)obj;
Phases oldPhase = (Phases)e.OldValue;
Phases newPhase = (Phases)e.NewValue;
//Probably want to use Collapsed as apposed to Hidden for UI Measure/Arrange purposes
switch (oldPhase)
{
case Phases.Phase1:
element.Window1Visibility = Visibility.Hidden;
break;
case Phases.Phase2:
element.Window2Visibility = Visibility.Hidden;
break;
case Phases.Phase3:
//element.Window3Visiblity = Visibility.Hidden;
break;
default:
//??
break;
}
switch (newPhase)
{
case Phases.Phase1:
element.Window1Visibility = Visibility.Visible;
break;
case Phases.Phase2:
element.Window2Visibility = Visibility.Visible;
break;
case Phases.Phase3:
//element.Window3Visiblity = Visibility.Visible;
break;
default:
//??
break;
}
}
//...
}
}
Take note that you'll also probably want to use Visiblity.Collapsed as apposed to Visiblity.Hidden ... Collapsed not only hides the object, but it does not affect the Measurement/Arrangement of other UIElements. Hidden affects the Measurement and Arrangement of other elements, but it doesn't actually draw the element (think of it more along the lines of "Invisible").