[Unity] VisualStateManager
Posted: 08 Sep 2014, 03:02
Hello,
I just came across another few problems. I tried to style a button and add some animations. Doing this using triggers worked fine, but not when I tried to use the suggested VisualStateManager. Unfortunately I'm not really that familiar with the VisualStateManager as I'm more used to triggers. But I looked up some examples and made some smaller changes to my xaml to get it working but unfortunately with a few issues.
1. I have to add another parent element such as a Grid where I have to add the VisualStateManager (VSM) elements to. If I add the VSM elements inside the border element it won't animate anything. But according to this MS example it could also be inside. But this is just a minor annoyance.
2. A bit more annoying is that I'm not allowed to use neither a StaticResource nor a DynamicResource for the To-Proper of the ColorAnimation. It then comes up with the following error message:
Following parts of the xaml I use:
I just came across another few problems. I tried to style a button and add some animations. Doing this using triggers worked fine, but not when I tried to use the suggested VisualStateManager. Unfortunately I'm not really that familiar with the VisualStateManager as I'm more used to triggers. But I looked up some examples and made some smaller changes to my xaml to get it working but unfortunately with a few issues.
1. I have to add another parent element such as a Grid where I have to add the VisualStateManager (VSM) elements to. If I add the VSM elements inside the border element it won't animate anything. But according to this MS example it could also be inside. But this is just a minor annoyance.
2. A bit more annoying is that I'm not allowed to use neither a StaticResource nor a DynamicResource for the To-Proper of the ColorAnimation. It then comes up with the following error message:
Code: Select all
Exception: Loading Assets/Resources/Gui/Views/Main/MainView.xaml
'.?AV?$BoxedValueImpl@VColor@Drawing@Noesis@@@Boxing@Core@Noesis@@' is not a valid value for the property 'To'
Noesis.Error.Check () (at Assets/Plugins/Proton/Gui/Noesis.Lib/Core/NoesisError.cs:60)
NoesisGUISystem.Noesis_LoadXAML (System.IntPtr& root, System.String xamlFile) (at Assets/Plugins/Proton/Gui/Noesis.Lib/Core/NoesisGUISystem.cs:314)
NoesisGUISystem.Load[FrameworkElement] (System.String xamlFile) (at Assets/Plugins/Proton/Gui/Noesis.Lib/Core/NoesisGUISystem.cs:90)
NoesisGUISystem.LoadXaml[FrameworkElement] (System.String xamlFile) (at Assets/Plugins/Proton/Gui/Noesis.Lib/Core/NoesisGUISystem.cs:34)
NoesisGUIPanel.OnEnable () (at Assets/Plugins/Proton/Gui/Noesis.Lib/NoesisGUIPanel.cs:149)
Code: Select all
<Style TargetType="Button">
<Setter Property="BorderBrush" Value="{DynamicResource ControlBorderBrush}" />
<Setter Property="Background" Value="{DynamicResource ControlBackgroundBrush}" />
<Setter Property="Foreground" Value="{DynamicResource ControlForegroundBrush}" />
<Setter Property="HorizontalAlignment" Value="Stretch" />
<Setter Property="VerticalAlignment" Value="Stretch" />
<Setter Property="HorizontalContentAlignment" Value="Center" />
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualStateGroup.Transitions>
<VisualTransition To="Normal" GeneratedDuration="0:0:0.25" />
<VisualTransition To="MouseOver" GeneratedDuration="0:0:0.25" />
</VisualStateGroup.Transitions>
<VisualState x:Name="Normal" />
<VisualState x:Name="MouseOver">
<Storyboard>
<ColorAnimation Storyboard.TargetName="Border" Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)" To="Red" />
</Storyboard>
</VisualState>
<VisualState x:Name="Pressed" />
<VisualState x:Name="Disabled"/>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Border x:Name="Border" HorizontalAlignment="{TemplateBinding HorizontalAlignment}" VerticalAlignment="{TemplateBinding VerticalAlignment}"
Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}">
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
</Border>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>