如何使CompositeStateTrigger与AdaptiveTrigger和DeviceFamilyStateTrigger UWP一起使用

时间:2016-09-28 16:10:10

标签: xaml triggers uwp uwp-xaml visualstatemanager

我正在努力让AdaptiveTriggerDeviceFamilyStateTriggerCompositeStateTrigger合作。

发现这个useful link引导了我,但仍无法使其发挥作用

我在GitHub上创建了一个示例项目来重现my issue here

供参考,这是我的XAML。我错过了什么?

<Grid Background="AliceBlue" x:Name="gridRoot">
    <VisualStateManager.VisualStateGroups>
        <VisualStateGroup >
            <VisualState x:Name="narrow">
                <VisualState.StateTriggers>
                    <triggers:CompositeStateTrigger Operator="And">
                        <mytrigger:AdaptiveTrigger MinWindowWidth="0" MaxWindowHeight="520" />
                        <triggers:DeviceFamilyStateTrigger DeviceFamily="Desktop" />
                    </triggers:CompositeStateTrigger>
                </VisualState.StateTriggers>
                <VisualState.Setters>
                    <Setter Target="textBlock.Text" Value="Desktop is narrow" />
                </VisualState.Setters>
            </VisualState>
            <VisualState x:Name="medium">
                <VisualState.StateTriggers>
                    <triggers:CompositeStateTrigger Operator="And">
                        <mytrigger:AdaptiveTrigger MinWindowWidth="521" MaxWindowHeight="1199" />
                        <triggers:DeviceFamilyStateTrigger DeviceFamily="Desktop" />
                    </triggers:CompositeStateTrigger>
                </VisualState.StateTriggers>
                <VisualState.Setters>
                    <Setter Target="textBlock.Text" Value="Desktop is medium width" />
                </VisualState.Setters>
            </VisualState>
            <VisualState x:Name="wide">
                <VisualState.StateTriggers>
                    <triggers:CompositeStateTrigger Operator="And">
                        <mytrigger:AdaptiveTrigger MinWindowWidth="1200"/>
                        <triggers:DeviceFamilyStateTrigger DeviceFamily="Desktop" />
                    </triggers:CompositeStateTrigger>
                </VisualState.StateTriggers>
                <VisualState.Setters>
                    <Setter Target="textBlock.Text" Value="Desktop is wide" />
                </VisualState.Setters>
            </VisualState>
        </VisualStateGroup>
    </VisualStateManager.VisualStateGroups>

    <Grid x:Name="gridText">
        <TextBlock x:Name="textBlock" FontSize="40" Text="My Text Block" Style="{StaticResource HeaderTextBlockStyle}" FontWeight="ExtraBold"/>
    </Grid>

</Grid>

1 个答案:

答案 0 :(得分:1)

您的代码几乎是正确的。这里的问题是您在<configuration> <packageSources> <add key="Living" value="C:\NugetRepository" /> </packageSources> <packageRestore> <add key="enabled" value="True" /> <add key="automatic" value="True" /> </packageRestore> <activePackageSource> <add key="Living" value="C:\NugetRepository" /> </activePackageSource> </configuration> 中设置了错误的属性。在AdaptiveTrigger中,我们应该设置AdaptiveTrigger MaxWindowWidth ,而不是MinWindowWidth

因此,您可以更改代码,如下所示,它应该能够正常工作。

MaxWindowHeight