首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Silverlight VisualStateManager

Silverlight VisualStateManager
EN

Stack Overflow用户
提问于 2010-01-28 21:54:22
回答 2查看 673关注 0票数 2

有没有可能有嵌套的视觉状态。我的意思是,如果一个ParentControl有一个ChildControl,并且两者都有自己的可视状态,那么是否可以通过设置ParentControl的状态来相应地更改ChildControl的状态。

EN

回答 2

Stack Overflow用户

发布于 2010-01-28 23:04:27

您需要调用GoToState方法来更改子控件的可视状态。

因为你需要调用一个方法,所以你不能在父控件的可视化状态管理器中使用序列图像板,因为它们只能动画显示属性。

因此,您需要在子控件中编写一些代码。来监视父级的状态并做出适当的响应。

有许多不同的方法可以做到这一点,但关键的信息是使用VisualStateManager.GetVisualStateGroups方法找到您感兴趣的父级上的VisualStateGroup,然后附加到该组的CurrentStateChanging事件。因此,当父控件将其感兴趣的状态转换到某个状态时,可以通知该子控件中的代码,并且可以针对其自身适当地调用GoToState

票数 1
EN

Stack Overflow用户

发布于 2010-01-29 01:18:47

我只需要声明一个新的依赖属性:

代码语言:javascript
复制
    public static readonly DependencyProperty StateProperty = 
        DependencyProperty.Register("State", 
        typeof( string ),                           
        typeof( TextBlockControl ),
        new PropertyMetadata("Top", 
        new PropertyChangedCallback(StateChanged)));

    [Category("DigItOut"), Description("State")]
    public string State
    {
        get
        {
            return this.GetValue(StateProperty).ToString();
        }
        set
        {
            this.SetValue(StateProperty, value);
        }
    }

    private static void StateChanged(DependencyObject sender, DependencyPropertyChangedEventArgs args)    
    {
        if (!String.IsNullOrEmpty(args.NewValue.ToString()))
            VisualStateManager.GoToState(sender as TextBlockControl, args.NewValue.ToString(), true);
    }

然后从它的parents状态设置它:

代码语言:javascript
复制
<VisualStateManager.VisualStateGroups>
        <VisualStateGroup x:Name="States">
            <VisualState x:Name="Reverse">
                <Storyboard>
                    <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="textBlockControl" Storyboard.TargetProperty="(TextBlockControl.State)">
                        <DiscreteObjectKeyFrame KeyTime="00:00:00">
                            <DiscreteObjectKeyFrame.Value>
                                <System:String>Bottom</System:String>
                            </DiscreteObjectKeyFrame.Value>
                        </DiscreteObjectKeyFrame>
                    </ObjectAnimationUsingKeyFrames>
                </Storyboard>
            </VisualState>
            <VisualState x:Name="Straight"/>
        </VisualStateGroup>
    </VisualStateManager.VisualStateGroups>

但是,如果我仍然希望控制转换的使用,那么我必须找到另一个解决方案。可能是第二处房产。

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

https://stackoverflow.com/questions/2154936

复制
相关文章

相似问题

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