有没有办法使用VisualStateManager我ChildWindow子类? 调用VisualStateManager什么也不做,和谷歌上搜索我也隐含实现这一目标是有手动调用故事板的唯一途径。 这是这么多更模糊而且容易出错。 有没有人找到了一种方法来实现呢?
更新了示例代码 。 要使用它,只需要创建一个新的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();
}
}
}