我正在使用XAML和C#制作一个Windows通用应用程序。我想使用可视状态触发器,下面的代码根据运行应用程序的设备的屏幕宽度对正文背景进行更改。
<VisualStateManager.VisualStateGroups>
<VisualStateGroup>
<VisualState x:Name="Phone">
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowWidth = "0"/>
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Target = "Body.Background"
Value = "#21539E" />
</VisualState.Setters>
</VisualState>
<VisualState x:Name="Tablets">
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowWidth = "720" />
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Target = "Body.Background"
Value = "Red" />
</VisualState.Setters>
</VisualState>
<VisualState x:Name="Laptop">
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowWidth = "1024" />
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Target = "Body.Background"
Value = "Black" />
</VisualState.Setters>
</VisualState>
<VisualState x:Name="PCs">
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowWidth = "1400" />
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Target = "Body.Background"
Value = "Green" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
但是当我为minimunwindow height属性做同样的事情时,它不起作用。
<VisualStateManager.VisualStateGroups>
<VisualStateGroup>
<VisualState x:Name="Phone">
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowHeight = "0"/>
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Target = "Body.Background"
Value = "#21539E" />
</VisualState.Setters>
</VisualState>
<VisualState x:Name="Tablets">
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowHeight = "120" />
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Target = "Body.Background"
Value = "Red" />
</VisualState.Setters>
</VisualState>
<VisualState x:Name="Laptop">
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowHeight = "1024" />
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Target = "Body.Background"
Value = "Black" />
</VisualState.Setters>
</VisualState>
<VisualState x:Name="PCs">
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowHeight = "1400" />
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Target = "Body.Background"
Value = "Green" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
我做错了什么,如何正确实现最小窗口高度?
答案 0 :(得分:0)
您的代码对我有用,唯一的问题是您可能没有看到与我相同的任何变化。
这是因为MinWindowHeight的大小在'effective pixels',而不是在你的显示器像素中,所以你无法像调整AdaptiveTrigger那样拉伸你的窗户。
尝试将MinWindowHeight尺寸更改为400,500,600,700,您将会看到它。