UWP - VisualStateManager.GoToState() 不起作用 [英] UWP - VisualStateManager.GoToState() does not work

查看:26
本文介绍了UWP - VisualStateManager.GoToState() 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我第一次使用 VisualStateManager.不幸的是,我没有让它运行.

I'm working the first time with the VisualStateManager. Unfortunatelly I don't get it running.

这是我的 XAML 代码:

This is my XAML-Code:

<SplitView x:Name="spltvw" IsPaneOpen="False" DisplayMode="CompactInline" 
               CompactPaneLength="48" Grid.Row="1" PaneBackground="#FFDADADA">
        <VisualStateManager.VisualStateGroups>
            <VisualStateGroup>
                <VisualState x:Name="lowerThan7State">
                    <VisualState.Setters>
                        <Setter Target="spltvw.DisplayMode" Value="Overlay" />
                    </VisualState.Setters>
                </VisualState>
                <VisualState x:Name="defaultState">
                    <VisualState.Setters>
                        <Setter Target="spltvw.DisplayMode" Value="CompactInline" />
                    </VisualState.Setters>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
        ....
</SplitView>

这是我的代码隐藏:

    private void Page_Loaded(object sender, RoutedEventArgs e)
    {
        bool test = false;
        if(IsScreenSizeLessThan7inches())
            test = VisualStateManager.GoToState(this, lowerThan7State.Name, true);
        else
            test = VisualStateManager.GoToState(this, defaultState.Name, true);
    }

我已经尝试更改useTransitions"参数.我已经调试并测试了IsScreenSizeLessThan7inches()"方法.但是这个方法的结果是正确的.

I've already tried to change the "useTransitions"-parameter. I've debugged and tested the the "IsScreenSizeLessThan7inches()" method. But the result of this method is correct.

GoToState() 方法的返回值始终为 false,SplittView-Control 的状态也不会改变.

The return value of the GoToState() method is always false and the state of the SplittView-Control is also not changed.

我没发现问题...

请帮我找出错误.

谢谢!

推荐答案

AVK 的评论很有帮助.

The comment of AVK was very helpfully.

我已将 VisualStateManager 放在 SplitView 之外,现在它可以工作了.

I've put the VisualStateManager outside of the SplitView and now it works.

这是我所做的:

<Grid Background="LightGray">
    <VisualStateManager.VisualStateGroups>
        <VisualStateGroup>
            <VisualState x:Name="lowerThan7State">
                <VisualState.Setters>
                    <Setter Target="spltvw.DisplayMode" Value="Overlay" />
                </VisualState.Setters>
            </VisualState>
            <VisualState x:Name="defaultState">
                <VisualState.Setters>
                    <Setter Target="spltvw.DisplayMode" Value="CompactInline" />
                </VisualState.Setters>
            </VisualState>
        </VisualStateGroup>
    </VisualStateManager.VisualStateGroups>
    <Grid.RowDefinitions>
        <RowDefinition Height="48"></RowDefinition>
        <RowDefinition Height="*"></RowDefinition>
    </Grid.RowDefinitions>
    <StackPanel Grid.Row="0" Background="#FFC31727" Orientation="Horizontal">
        <Button Name="btn_hamburger" Width="48" VerticalAlignment="Stretch" Click="btn_hamburger_Click">
            <FontIcon FontFamily="Segoe MDL2 Assets" Glyph="&#xE700;" Foreground="White" />
        </Button>
        <TextBlock Margin="10,0,80,0" FontSize="25" VerticalAlignment="Center" Foreground="White" FontWeight="Bold">
            ***-App
        </TextBlock>
    </StackPanel>
    <Grid Grid.Row="0" HorizontalAlignment="Right" Margin="0,0,4,0" VerticalAlignment="Center">
        <Image Source="ms-appx:///Assets/***_Logo_weiss.png" Height="44" />
    </Grid>
    <SplitView x:Name="spltvw" IsPaneOpen="False" DisplayMode="CompactInline" OpenPaneLength="250"
               CompactPaneLength="48" Grid.Row="1" PaneBackground="#FFDADADA" SizeChanged="spltvw_SizeChanged">
        ...
    </SplitView>

这篇关于UWP - VisualStateManager.GoToState() 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆