I've defined the following two states in Expression Blend. I've been trying to follow this guide but I feel like it leaves me hanging when I need information on how and when to change state.
According to the guide I am to attach a behaviour(I assume "GotoState") to my UserControl
- Unfortunately I don't think I actually have a User Control
- and even if I did, would I have to attach a behaviour to both my PortraitState
and my LandscapeState
?
It seems I can attach a GotoState
to my LayoutRoot
element. So do I attach my behaviour to that in both states? Any help would be greatly appreciated.
*edit: I was playing around in my xaml.cs file and figured that this might be the way to do it programmatically. when debugging and changing the orientation I enter my switch case and find the correct orientation. The state, however, is never switched. What am I doing wrong?
protected override void OnOrientationChanged(OrientationChangedEventArgs e)
{
switch (e.Orientation)
{
case PageOrientation.Landscape:
ExtendedVisualStateManager.GoToElementState(root:this.LayoutRoot, stateName: "LandscapeState", useTransitions: true);
break;
case PageOrientation.LandscapeRight:
ExtendedVisualStateManager.GoToElementState(root:this.LayoutRoot, stateName: "LandscapeState", useTransitions: true);
break;
case PageOrientation.LandscapeLeft:
ExtendedVisualStateManager.GoToElementState(root:LayoutRoot, stateName: "LandscapeState", useTransitions: true);
break;
case PageOrientation.Portrait:
ExtendedVisualStateManager.GoToElementState(root:this.LayoutRoot, stateName: "PortraitState", useTransitions: true);
break;
case PageOrientation.PortraitUp:
ExtendedVisualStateManager.GoToElementState(root:this.LayoutRoot, stateName: "PortraitState", useTransitions: true);
break;
case PageOrientation.PortraitDown:
ExtendedVisualStateManager.GoToElementState(root:this.LayoutRoot, stateName: "PortraitState", useTransitions: true);
break;
default:
break;
}
}
edit2: When attempting the above It seems that GotoElementState returns false and, according to MSDN: "returns true if the control successfully transitioned to the new state; otherwise, false."
Now I'm left with the question : What can cause my state transition to fail?