有任何方法可以在我的VisualStateManager子类中使用ChildWindow吗?对VisualStateManager的调用什么也不做,而我所做的googling暗示了实现这一目标的唯一方法是手动调用故事板。这太草率了,而且容易出错。有没有人找到办法来实现这一目标?
用示例代码更新。要使用它,只需创建一个新的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();
}
}
}发布于 2010-01-25 16:29:50
到目前为止,我发现的唯一解决办法是将任何需要视觉状态的东西放入UserControl中。UserControl可以拥有状态,并成功地在它们之间切换,并通过事件、方法和属性向ChildWindow传递任何必需的信息。
发布于 2010-10-01 02:36:23
检查这篇文章在Silverlight工具包的子Windows控件中使用
发布于 2010-02-24 08:24:43
与Dov一样,我在ChildWindows中没有使用VSM时也遇到了同样的问题。我所做的是将我的ChildWindow转换为UserControl,然后在打开它之前将UserControl设置为泛型ChildWindow的内容。
var childWindow = new ChildWindow { Content = someUserControl };现在的问题是,您失去了DialogResult类的ChildWindow功能,因为您的代码匹配将在UserControl中。访问DialogResult属性的最简单方法是只使用UserControl内部的父属性。
https://stackoverflow.com/questions/2118814
复制相似问题