Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何设置嵌套元素的可视状态?_C#_Wpf_Xaml_Microsoft Metro - Fatal编程技术网

C# 如何设置嵌套元素的可视状态?

C# 如何设置嵌套元素的可视状态?,c#,wpf,xaml,microsoft-metro,C#,Wpf,Xaml,Microsoft Metro,我正在尝试使用VisualStateManager为属性设置值。问题是我需要在嵌套元素(称为variableSizedWrapGrid)上设置此值,但它不响应相应的状态。这个想法是当用户更改平板电脑的方向(从横向到纵向)时,应该更改此元素的方向 <GroupStyle.Panel> <ItemsPanelTemplate> <VariableSizedWrapGrid x:Name="variableSizedWrapGrid" Orient

我正在尝试使用VisualStateManager为属性设置值。问题是我需要在嵌套元素(称为variableSizedWrapGrid)上设置此值,但它不响应相应的状态。这个想法是当用户更改平板电脑的方向(从横向到纵向)时,应该更改此元素的方向

<GroupStyle.Panel>
    <ItemsPanelTemplate>
        <VariableSizedWrapGrid x:Name="variableSizedWrapGrid" Orientation="Vertical" Background="Blue" Width="660" ItemHeight="120" ItemWidth="220" Margin="0,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应用程序。

我相信这就是LayoutWarePage的用途。如果将LayoutWarePage作为基类,并且希望控件在平板电脑旋转时切换视觉状态,则可以将控件的加载事件挂接到LayoutWarePage上的StartAyoutUpdates方法

如您所见,每当状态更改时,它都会运行“InvalidateVisualState”,它将遍历所有接收LayoutUpdate的控件,并手动将其VisualStateManager设置为适当的状态

因此,在这里的代码中,您需要为景观设置一个VisualState—我相信它将被称为FullScreenSraft,但我不记得了—然后向VariableSizedWrapGrid控件的已加载事件添加StartayOutUpdates。这是假设您的页面是LayoutWarePage。老实说,如果你想这么做,你应该这么做。出于这个原因,他们包含了所有的样板代码

希望有帮助