我正在制作一个UWP应用,其中我需要在同一页面上针对不同屏幕尺寸的不同动画。我想如果屏幕宽度小于400这个动画应该播放,如果屏幕与小于720其他动画应该播放。如何在C#中编写代码。
答案 0 :(得分:0)
使用带有StateTriggers
的AdaptiveTrigger
属性可以根据窗口大小在XAML标记中创建声明性规则,从而获得所需内容。例如:
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup>
<VisualState>
<VisualState.StateTriggers>
<!-- VisualState to be triggered when window width is <400. -->
<AdaptiveTrigger MinWindowWidth="0" />
</VisualState.StateTriggers>
<VisualState.Storyboard>
<Storyboard>
<!-- The animation you want to play. -->
</Storyboard>
</VisualState.Storyboard>
</VisualState>
<VisualState>
<VisualState.StateTriggers>
<!-- VisualState to be triggered when window width is >=400 and <720. -->
<AdaptiveTrigger MinWindowWidth="400" />
</VisualState.StateTriggers>
<VisualState.Storyboard>
<Storyboard>
<!-- The animation you want to play. -->
</Storyboard>
</VisualState.Storyboard>
</VisualState>
<VisualState>
<VisualState.StateTriggers>
<!-- VisualState to be triggered when window width is >=720. -->
<AdaptiveTrigger MinWindowWidth="720" />
</VisualState.StateTriggers>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
...
</Grid>
答案 1 :(得分:-1)
我认为您可以使用SystemParameters.Workarea或System.Windows.Forms.WorkingArea。从其中任何一个都可以访问宽度属性。
https://msdn.microsoft.com/en-us/library/system.windows.systemparameters.workarea.aspx
https://msdn.microsoft.com/en-us/library/system.windows.forms.screen.workingarea(v=vs.110).aspx