加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 如何在嵌套元素上设置可视状态?

发布时间:2020-12-15 21:33:19 所属栏目:百科 来源:网络整理
导读:我正在尝试使用VisualStateManager为属性设置一个值.问题是我需要在嵌套元素(称为variableSizedWrapGrid)上设置此值,但它不响应相应的状态.这个想法是当用户更改平板电脑的方向(LANDSCAPE到PORTRAIT)时,应该更改此元素的方向. GroupStyle.Panel ItemsPanelTe
我正在尝试使用VisualStateManager为属性设置一个值.问题是我需要在嵌套元素(称为variableSizedWrapGrid)上设置此值,但它不响应相应的状态.这个想法是当用户更改平板电脑的方向(LANDSCAPE到PORTRAIT)时,应该更改此元素的方向.

<GroupStyle.Panel>
    <ItemsPanelTemplate>
        <VariableSizedWrapGrid x:Name="variableSizedWrapGrid" Orientation="Vertical" Background="Blue" Width="660" ItemHeight="120" ItemWidth="220" Margin="0,80,0">

            <VisualStateManager.VisualStateGroups>
                <VisualStateGroup>
                    <VisualState x:Name="FullScreenPortrait">
                        <Storyboard>
                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Orientation)">
                                <DiscreteObjectKeyFrame KeyTime="0" Value="Horizontal" />
                            </ObjectAnimationUsingKeyFrames>
                        </Storyboard>
                    </VisualState>
                </VisualStateGroup>
            </VisualStateManager.VisualStateGroups>

        </VariableSizedWrapGrid>

    </ItemsPanelTemplate>
</GroupStyle.Panel>

我正在为Windows 8开发Windows Metro应用程序.

解决方法

我相信这是LayoutAwarePage的用途.如果您将LayoutAwarePage作为基类,并且希望控件在旋转平板电脑时切换VisualStates,则将控件的Loaded事件挂钩到LayoutAwarePage上的StartLayoutUpdates方法.

如您所见,每当状态发生变化时,它将运行“InvalidateVisualState”,它将遍历接收LayoutUpdates的所有控件,并手动将其VisualStateManager设置为适当的状态.

所以在你所拥有的代码中,你需要为景观设置一个VisualState – 我相信它将被称为FullScreenLandscape但我不记得了 – 然后将StartLayoutUpdates添加到VariableSizedWrapGrid控件的Loaded事件中.这假设您的页面是LayoutAwarePage.老实说,如果你想这样做,你应该这样做.由于这个原因,他们已经包含了所有样板代码.

希望有所帮助.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读