Are VisualStates supported in UserControl?
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?
-
-
sfernandez
Site Admin
- Posts: 3197
- Joined:
Re: Are VisualStates supported in UserControl?
It seems that we are not able to find the VisualStateGroup when using VisualStateManager.GoToState() on a UserControl. We will try to fix it as soon as possible.
Meanwhile you should use then VisualStateManager.GoToElementState() by providing the root element that contains the VisualStateGroup. In your example, that root would be the Border named "realtimeDataPanel".
Meanwhile you should use then VisualStateManager.GoToElementState() by providing the root element that contains the VisualStateGroup. In your example, that root would be the Border named "realtimeDataPanel".
Code: Select all
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 Noesis.Border stateGroup;
public void OnPostInit()
{
this.stateGroup = FindName<Noesis.Border>("realtimeDataPanel");
}
private void OnStateChanged(RealtimeState state)
{
Debug.Log("RealtimeState = " + state.ToString());
VisualStateManager.GoToElementState(this.stateRoot, state.ToString(), false);
}
}
}
Re: Are VisualStates supported in UserControl?
Thanks a lot! It works fine now!
Who is online
Users browsing this forum: Ahrefs [Bot], Google [Bot] and 16 guests