如何使用VisualStates在ChildWindow? [英] How can I use VisualStates in a ChildWindow?
问题描述
有没有办法使用VisualStateManager我ChildWindow子?调用VisualStateManager什么也不做,和谷歌上搜索我没有暗示要实现这一目标是有手动调用故事板的唯一途径。这是这么多的更模糊,而且容易出错。有没有人找到了一种方法来实现呢?
更新,其中例如code 。要使用它,只需要创建一个新的Silverlight项目,并从主页上点击一个按钮调用ExampleWindow.ShowWindow()。你会看到按钮,即使构造函数应该隐藏按钮的状态。
XAML(ExampleWindow.xaml):
<控制:ChildWindow
的xmlns =http://schemas.microsoft.com/winfx/2006/xaml/$p$psentation
的xmlns:X =http://schemas.microsoft.com/winfx/2006/xaml
的xmlns:控制=CLR的命名空间:System.Windows.Controls;装配= System.Windows.Controls的
的xmlns:D =http://schemas.microsoft.com/ex$p$pssion/blend/2008的xmlns:MC =http://schemas.openxmlformats.org/markup-compatibility/2006
MC:可忽略=D
xmlns:ic=\"clr-namespace:Microsoft.Ex$p$pssion.Interactivity.Core;assembly=Microsoft.Ex$p$pssion.Interactions\"
X:类=Client.Windows.ExampleWindow
标题=示例>
<电网X:NAME =LayoutRoot>
< VisualStateManager.VisualStateGroups>
< VisualStateGroup X:NAME =ExampleStateGroup>
<的VisualState X:NAME =ExampleBaseState>
<情节提要>
&所述; DoubleAnimationUsingKeyFrames的BeginTime =00:00:00播放时间=00:00:00.0010000Storyboard.TargetName =键Storyboard.TargetProperty =(UIElement.Opacity)>
&所述; EasingDoubleKeyFrame KeyTime =00:00:00值=0/>
< / DoubleAnimationUsingKeyFrames>
< /故事板>
< /&的VisualState GT;
< / VisualStateGroup>
< /VisualStateManager.VisualStateGroups>
< VisualStateManager.CustomVisualStateManager>
< IC:ExtendedVisualStateManager />
< /VisualStateManager.CustomVisualStateManager>
<按钮X:NAME =按钮CONTENT =你应该看不到我Grid.ColumnSpan =2WIDTH =150HEIGHT =150的HorizontalAlignment =中心VerticalAlignment =中心/>
< /网格和GT;
< /控制:ChildWindow>
code背后(ExampleWindow.xaml.cs):
使用System.Windows;
使用System.Windows.Controls的;命名空间Client.Windows
{
公共部分类ExampleWindow:ChildWindow
{
公共ExampleWindow()
{
的InitializeComponent(); VisualStateManager.GoToState(这一点,ExampleBaseState,真正的);
} 公共静态无效的ShowWindow()
{
变种W =新ExampleWindow();
w.Show();
}
}
}
到目前为止,我已经找到了唯一的解决方法就是把任何事情需要可视状态到用户控件。用户控件可以有状态,以及它们之间的切换成功,并通过事件,方法和属性的沟通需要的事情到ChildWindow。
Is there any way to use the VisualStateManager with my ChildWindow subclass? Calls to VisualStateManager do nothing, and the googling I did implied the only way to achieve this is with manual calls to Storyboards. That's so much sloppier and prone to error. Has anyone found a way to achieve it?
Updated with example code. To use it, just create a new Silverlight Project, and call ExampleWindow.ShowWindow() from a button click on the main page. You'll see the button, even though the constructor sets the state that should hide the button.
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>
Code Behind (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();
}
}
}
So far, the only workaround I've found is to put anything that requires visual states into a UserControl. The UserControl can have states, and successfully switch between them, and communicate anything necessary to the ChildWindow through events, methods, and properties.
这篇关于如何使用VisualStates在ChildWindow?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!