视觉状态管理器无响应最大化/最小化按钮

时间:2017-01-01 03:17:35

标签: c# uwp-xaml

我在为UWP玩弄/学习视觉状态管理器。当我点击应用程序上的最大化/最小化按钮时,我有一段代码不响应触发器/设置器。如果我手动调整盒子的大小,它会很好地响应。

我有第二段代码,当我点击最大化/最小化按钮时,它会响应触发/设置器。

这两个代码看起来与我完全相同,但似乎我遗漏了一些东西。提前感谢您的帮助

以下是无法响应最大化/最小化按钮的代码:

 <Grid Name="MyGrid" Background="White">

    <VisualStateManager.VisualStateGroups>
        <VisualStateGroup x:Name="Groups">
            <VisualState x:Name="WindowsPhone">
                <VisualState.StateTriggers>
                    <AdaptiveTrigger MinWindowWidth="0"/>
                </VisualState.StateTriggers>
                <VisualState.Setters>
                    <Setter Target="MySplitView.DisplayMode" Value="Inline"/>
                    <Setter Target="HamburgerButton.Width" Value="100"/>
                    <Setter Target="MyGrid.Background" Value="LightBlue"/>
                    <Setter Target="AutoSuggestBox.Visibility" Value="Compact"/>
                </VisualState.Setters>
            </VisualState>
            <VisualState x:Name="WindowsTablet">
                <VisualState.StateTriggers>
                    <AdaptiveTrigger MinWindowWidth="600"/>
                </VisualState.StateTriggers>
                <VisualState.Setters>
                    <Setter Target="MySplitView.DisplayMode" Value="Overlay"/>
                    <Setter Target="AutoSuggestBox.Visibility" Value="Visible"/>
                    <Setter Target="MyGrid.Background" Value="HotPink"/>
                </VisualState.Setters>
            </VisualState>
            <VisualState x:Name="Desktop">
                <VisualState.StateTriggers>
                    <AdaptiveTrigger MinWindowWidth="800"/>                        
                </VisualState.StateTriggers>
                <VisualState.Setters>                  
                    <Setter Target="MyGrid.Background" Value="Orange"/>
                </VisualState.Setters>
            </VisualState>
        </VisualStateGroup>
    </VisualStateManager.VisualStateGroups>



    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>


    <RelativePanel>
        <Button Name="HamburgerButton"
                Width="50"
                Height="50"
                Click="HamburgerButton_Click"
                FontFamily="Segoe MDL2 Assets"
                Content="&#xE700;"
                RelativePanel.AlignLeftWithPanel="True"/>

        <AutoSuggestBox Name="AutoSuggestBox"
                        QueryIcon="Find"
                        PlaceholderText="Search"
                        Width="200"                                  
                        RelativePanel.AlignRightWithPanel="True"
                        Margin="0,10,0,0"/>


    </RelativePanel>

    <SplitView Grid.Row="1"
               Name="MySplitView"
               IsPaneOpen="False"
               CompactPaneLength="50"
               OpenPaneLength="200"
               DisplayMode="CompactOverlay">


        <SplitView.Pane>
            <ListBox Name="MylistBox"
                     SelectionMode="Single"
                     SelectionChanged="MylistBox_SelectionChanged">
                <ListBoxItem>
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Name="FirstIcon"
                                   FontFamily="Segoe MDL2 Assets"
                                   FontSize="30"
                                   Text="&#xE80F;"/>
                        <TextBlock Name="TextTextBlock"
                                   FontSize="20"
                                   Text="Hello"
                                   FontWeight="Bold"
                                   Margin="20,0,0,0"/>
                    </StackPanel>
                </ListBoxItem>
                <ListBoxItem>
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Name="SecondIcon"
                                   FontFamily="Segoe MDL2 Assets"
                                   FontSize="30"
                                   Text="&#xE80F;"/>

                        <TextBlock Name="SeconTextBlock"
                                   FontFamily="20"
                                   Text="Hello Again"
                                   FontWeight="Bold"
                                   Margin="20,0,0,0"/>
                    </StackPanel>
                </ListBoxItem>
            </ListBox>
        </SplitView.Pane>


    </SplitView>

</Grid>

这是可行的代码:

 <Grid Name="ColorGrid" Background="Pink">
    <VisualStateManager.VisualStateGroups>
        <VisualStateGroup x:Name="VisualStateGroup">
            <VisualState x:Name="VisualStatePhone">
                <VisualState.StateTriggers>
                    <AdaptiveTrigger MinWindowWidth="0"/>
                </VisualState.StateTriggers>
                 <VisualState.Setters>
                    <Setter Target="ColorGrid.Background" Value="Red"/>
                    <Setter Target="MessageTextBlock.FontSize" Value="18"/>
                </VisualState.Setters>
            </VisualState>
            <VisualState x:Name="VisualStateTablet">
                <VisualState.StateTriggers>
                    <AdaptiveTrigger MinWindowWidth="600"/>
                </VisualState.StateTriggers>
                <VisualState.Setters>
                    <Setter Target="ColorGrid.Background" Value="Yellow"/>
                    <Setter Target="MessageTextBlock.FontSize" Value="40"/>
                </VisualState.Setters>
            </VisualState>
            <VisualState x:Name="VisualStateDesktop">
                <VisualState.StateTriggers>
                    <AdaptiveTrigger MinWindowWidth="800"/>
                </VisualState.StateTriggers>
                <VisualState.Setters>
                    <Setter Target="ColorGrid.Background" Value="Blue"/>
                    <Setter Target="MessageTextBlock.FontSize" Value="60"/>
                </VisualState.Setters>
            </VisualState>
        </VisualStateGroup>
    </VisualStateManager.VisualStateGroups>

    <TextBlock Name="MessageTextBlock" Text="Hello I am forgetting something"/>

</Grid>

1 个答案:

答案 0 :(得分:0)

@BoltClock我甚至更奇怪的是我创建了另一个项目,这个项目对最大化和最小化按钮做出了很好的响应,但是当我手动调整大小时,它不响应&#34; Tablet&#34;状态。

如果我从开始屏幕启动,一切正常。

`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    </VisualStateManager.VisualStateGroups>

    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>



    <RelativePanel>
        <Button Name="HamburgerButton"
            Height="50"
            Width="50"
            FontFamily="Segoe MDL2 Assets"
            Content="&#xE700;"
            RelativePanel.AlignLeftWithPanel="True"
            Click="HamburgerButton_Click_1"/>

        <AutoSuggestBox Name="AutoSuggest"
                        Width="200"
                        QueryIcon="Find"
                        PlaceholderText="Search"
                        RelativePanel.AlignRightWithPanel="True"
                        Margin="0,10,0,0"
                        />

        <TextBlock Name="TitleTextBlock"
                   FontSize="30"
                   FontWeight="Bold"
                   RelativePanel.RightOf="HamburgerButton"
                   Text="Home"/>
    </RelativePanel>


    <SplitView Name="MySplitView"
               Grid.Row="1"
               OpenPaneLength="200"
               CompactPaneLength="50"
               DisplayMode="CompactOverlay">
        <SplitView.Pane>
            <ListBox SelectionMode="Single"
                     SelectionChanged="ListBox_SelectionChanged"
                    >
                <ListBoxItem>
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Name="FirstIcon"
                                   FontFamily="Segoe MDL2 Assets"
                                   FontSize="30"
                                   Text="&#xE80F;"/>
                        <TextBlock Name="FirstText"
                                   FontSize="20"
                                   Text="Hello"
                                   FontWeight="Bold"
                                   Margin="10,0,0,0"/>
                    </StackPanel>
                </ListBoxItem>
                <StackPanel Orientation="Horizontal">
                    <TextBlock Name="SecondIcon"
                               FontFamily="Segoe MDL2 Assets"
                               FontSize="30"
                               Text="&#xE80F;"/>
                    <TextBlock Name="SecondText"
                               FontSize="20"
                               Text="Hello Again"
                               FontWeight="Bold"
                               Margin="10,0,0,0"/>

                </StackPanel>
                <ListBoxItem>
                    <StackPanel>
                        <TextBlock/>
                        <TextBlock/>
                    </StackPanel>
                </ListBoxItem>

            </ListBox>
        </SplitView.Pane>

    </SplitView>

</Grid>`