首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在VisualStates中使用ChildWindow?

如何在VisualStates中使用ChildWindow?
EN

Stack Overflow用户
提问于 2010-01-22 16:41:58
回答 4查看 1.7K关注 0票数 1

有任何方法可以在我的VisualStateManager子类中使用ChildWindow吗?对VisualStateManager的调用什么也不做,而我所做的googling暗示了实现这一目标的唯一方法是手动调用故事板。这太草率了,而且容易出错。有没有人找到办法来实现这一目标?

用示例代码更新。要使用它,只需创建一个新的Silverlight项目,并通过单击主页上的按钮调用ExampleWindow.ShowWindow()。您将看到按钮,即使构造函数设置了应该隐藏按钮的状态。

XAML (ExampleWindow.xaml):

代码语言:javascript
复制
<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):

代码语言:javascript
复制
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();
        }
    }
}
EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2010-01-25 16:29:50

到目前为止,我发现的唯一解决办法是将任何需要视觉状态的东西放入UserControl中。UserControl可以拥有状态,并成功地在它们之间切换,并通过事件、方法和属性向ChildWindow传递任何必需的信息。

票数 0
EN

Stack Overflow用户

发布于 2010-10-01 02:36:23

检查这篇文章在Silverlight工具包的子Windows控件中使用

票数 1
EN

Stack Overflow用户

发布于 2010-02-24 08:24:43

与Dov一样,我在ChildWindows中没有使用VSM时也遇到了同样的问题。我所做的是将我的ChildWindow转换为UserControl,然后在打开它之前将UserControl设置为泛型ChildWindow的内容。

代码语言:javascript
复制
var childWindow = new ChildWindow { Content = someUserControl };

现在的问题是,您失去了DialogResult类的ChildWindow功能,因为您的代码匹配将在UserControl中。访问DialogResult属性的最简单方法是只使用UserControl内部的父属性。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2118814

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档