有什么方法可以将 VisualStateManager 与我的 ChildWindow 子类一起使用?对 VisualStateManager 的调用什么都不做,而我所做的谷歌搜索暗示实现这一点的唯一方法是手动调用 Storyboards。这太草率了,而且容易出错。有没有人找到实现它的方法?
更新了示例代码。要使用它,只需创建一个新的 Silverlight 项目,然后通过单击主页上的按钮调用 ExampleWindow.ShowWindow()。即使构造函数设置了应该隐藏按钮的状态,您也会看到该按钮。
XAML(ExampleWindow.xaml):
<controls:ChildWindow
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
xmlns:ic="clr-namespace:Microsoft.Expression.Interactivity.Core;assembly=Microsoft.Expression.Interactions"
x:Class="Client.Windows.ExampleWindow"
Title="Example">
<Grid x:Name="LayoutRoot">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="ExampleStateGroup">
<VisualState x:Name="ExampleBaseState">
<Storyboard>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="button" Storyboard.TargetProperty="(UIElement.Opacity)">
<EasingDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<VisualStateManager.CustomVisualStateManager>
<ic:ExtendedVisualStateManager/>
</VisualStateManager.CustomVisualStateManager>
<Button x:Name="button" Content="You Shouldn't See Me" Grid.ColumnSpan="2" Width="150" Height="150" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Grid>
</controls:ChildWindow>
后面的代码(ExampleWindow.xaml.cs):
using System.Windows;
using System.Windows.Controls;
namespace Client.Windows
{
public partial class ExampleWindow : ChildWindow
{
public ExampleWindow()
{
InitializeComponent();
VisualStateManager.GoToState( this, "ExampleBaseState", true );
}
public static void ShowWindow()
{
var w = new ExampleWindow();
w.Show();
}
}
}