Are VisualStates supported in UserControl?
Posted: 18 Mar 2014, 07:44
Hi,
I'm trying to use VisualStates in my UserControl, but when I call VisualStateManager.GoToState nothing happens:
My UserControl is designed in Blend 2013, so it should be the correct XAML, it looks like this:
And the code behind is:
OnStateChanged is actually called, I see the debug output, but the visibility of the "coordinatesPanel" control is not changed. I tried to animate other properties like TextBlock.Text--it doesn't work as well.
Am I right that I use 'this' as a root element in UserControl to switch the VisualStates?
I'm trying to use VisualStates in my UserControl, but when I call VisualStateManager.GoToState nothing happens:
Code: Select all
VisualStateManager.GoToState(this, "SomeState", false);Code: Select all
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="My.UserControls.RealtimeData"
x:Name="realtimeDataRoot"
d:DesignWidth="450" d:DesignHeight="245">
<Border x:Name="realtimeDataPanel">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="RealtimeDataVisualStateGroup">
<VisualState x:Name="InitialState"/>
<VisualState x:Name="InitialAppleState">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="coordinatesPanel">
<DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Hidden}"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="InProgressState">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="coordinatesPanel">
<DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Hidden}"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="FailedState">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="coordinatesPanel">
<DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Hidden}"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="OKState"/>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Viewbox>
<StackPanel HorizontalAlignment="Center">
<Grid x:Name="coordinatesPanel" HorizontalAlignment="Center" VerticalAlignment="Center">
[...]
</Grid>
</StackPanel>
</Viewbox>
</Border>
</UserControl>Code: Select all
using UnityEngine;
using System;
using System.Collections;
using System.Runtime.InteropServices;
using Noesis;
namespace My.UserControls
{
[Noesis.Extended]
[Noesis.UserControlSource("Assets/Script/RealtimeData.xaml")]
public class RealtimeData : Noesis.UserControl
{
public enum RealtimeState { InitialState, InitialAppleState, InProgressState, FailedState, OKState };
...
private void OnStateChanged(RealtimeState state)
{
Debug.Log("RealtimeState = " + state.ToString());
VisualStateManager.GoToState(this, state.ToString(), false);
}
}
Am I right that I use 'this' as a root element in UserControl to switch the VisualStates?