I am trying to switch from using triggers and themes to VisualStateManager because it appears that WindowsRT is moving in this direction and I want to minimize the amount of code that is different. To that effect, I'm trying to set a simple scheme that will switch between large margins for a tablet device, such as the Surface 2, and normal looking margins for a desktop scheme. I know I can do this by setting the property directly on the object, but if I have 15 labels in a control, it's simply unsupportable to create a storyboard that sets the margin for every label. So I'm attempting to swap the styles on each of the labels with this code:
<VisualStateManager.VisualStateGroups>
<VisualStateGroup Name="DeviceStates">
<VisualState Name="Desktop"/>
<VisualState Name="TabletLandscape">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="FirstNameLabel"
Storyboard.TargetProperty="Style">
<DiscreteObjectKeyFrame KeyTime="0"
Value="{StaticResource TabletLabelStyle}"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
I've seen several examples in my search that show an almost identical pattern working in Silverlight and in Windows Store applications. When I try this in plain-old WPF, I get "This freezable cannot be frozen". I dug into the code with Reflector and Style is not derived from DependencyObject, so I'm confused about what's trying to be frozen. Does anyone have a clue what's going on here?