UWP AdaptiveTrigger minWindowWidth背景未更改

时间:2019-04-29 15:09:22

标签: .net xaml xamarin uwp

我正在学习UWP,并且以下代码不起作用:

<Page
    x:Class="LearningUWP.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:LearningUWP"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

    <Grid>
        <Grid>
            <VisualStateManager.VisualStateGroups>
                <VisualStateGroup>
                    <VisualState>
                        <VisualState.StateTriggers>
                            <AdaptiveTrigger MinWindowWidth="500" />
                        </VisualState.StateTriggers>

                        <VisualState.Setters>
                            <Setter Target="myStackPanel.Background" Value="Red" />
                        </VisualState.Setters>
                    </VisualState>
                </VisualStateGroup>
            </VisualStateManager.VisualStateGroups>

            <StackPanel x:Name="myStackPanel" Background="Blue" >
                <TextBlock Text="myTextBlock" />
            </StackPanel>
        </Grid>
    </Grid>
</Page>

我期望窗口width > 500时背景变为红色。但是,在扩展它时不起作用。如何解决?

1 个答案:

答案 0 :(得分:0)

首先将其移至顶部Grid

第二,您可能要为Setter添加MinWindowWidth="0"