请帮助我理解为什么VisualStateManager不会改变 UserControls窗口大小调整时的可见性。 我想在窗口调整大小时用一个用户控件替换另一个用户控件。
这是我的代码:
<Page
x:Class="Diagrams.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Diagrams"
xmlns:uc="using:Diagrams.UserControls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid x:Name="RootGrid" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<ContentControl>
<StackPanel>
<uc:MyUserControl1 x:Name="MyControl1" Visibility="Visible" Height="400" Width="900" />
<uc:MyUserControl1 x:Name="MyControl2" Visibility="Collapsed" Height="400" Width="900"/>
</StackPanel>
</ContentControl>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup>
<VisualState x:Name="Narrow">
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowWidth="0" />
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Target="RootGrid.Background" Value="White" />
<Setter Target="MyControl2.Visibility" Value="Collapsed" />
<Setter Target="MyControl1.Visibility" Value="Visible" />
<Setter Target="MyControl1.Background" Value="Black" />
</VisualState.Setters>
</VisualState>
<VisualState x:Name="WideScreen">
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowWidth="1080" />
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Target="RootGrid.Background" Value="Blue" />
<Setter Target="MyControl2.Visibility" Value="Visible" />
<Setter Target="MyControl1.Visibility" Value="Collapsed" />
<Setter Target="MyControl1.Background" Value="Red" />
</VisualState.Setters>
</VisualState>
<VisualState x:Name="Surface">
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowWidth="1921" />
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Target="RootGrid.Background" Value="Black" />
<Setter Target="MyControl2.Visibility" Value="Collapsed" />
<Setter Target="MyControl1.Visibility" Value="Visible" />
<Setter Target="MyControl1.Background" Value="Yellow" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Grid>