【发布时间】:2020-05-02 03:21:49
【问题描述】:
为什么我们没有这样简单的 UWP 响应助手?
我在单独的 .xaml 文件中有这些样式:
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Project.App.WindowsApp.Styles">
<Style x:Key="TextTitleH1" TargetType="TextBlock" >
<Setter Property="FontFamily" Value="Quicksand"/>
<Setter Property="FontWeight" Value="Light"/>
<Setter Property="FontSize" Value="30" />
</Style>
<Style x:Key="TextTitleH2" TargetType="TextBlock" >
<Setter Property="FontFamily" Value="Quicksand"/>
<Setter Property="FontWeight" Value="Light"/>
<Setter Property="FontSize" Value="24" />
</Style>
<Style x:Key="TextTitleH3" TargetType="TextBlock" >
<Setter Property="FontFamily" Value="Quicksand"/>
<Setter Property="FontWeight" Value="Normal"/>
<Setter Property="FontSize" Value="22" />
</Style>
<Style x:Key="TextTitleH4" TargetType="TextBlock" >
<Setter Property="FontFamily" Value="Quicksand"/>
<Setter Property="FontWeight" Value="Normal"/>
<Setter Property="FontSize" Value="16" />
</Style>
<Style x:Key="TextNormal" TargetType="TextBlock" >
<Setter Property="FontFamily" Value="Quicksand"/>
<Setter Property="FontWeight" Value="Light"/>
<Setter Property="FontSize" Value="16" />
</Style>
</ResourceDictionary>
我有一个使用这些样式的页面(为简单起见省略了很多代码):
<ScrollViewer >
<Grid>
...
<StackPanel>
<TextBlock Text="{Binding Source={CustomResource Page_Dashboard_LatestImage}}" Style="{StaticResource TextTitleH4}" />
...
<TextBlock Text="{CustomResource Page_Dashboard_NoImage}" Style="{StaticResource TextNormal}"/>
<TextBlock Text="{CustomResource Page_Dashboard_LatestImage_Description}" Style="{StaticResource TextNormal}" />
...
</StackPanel>
<StackPanel>
<TextBlock Text="{Binding Source={CustomResource Page_Dashboard_TipsTitle}} Style="{StaticResource TextTitleH4}" />
...
</StackPanel>
...
</Grid>
</ScrollViewer>
现在我可以给所有这些控件一个x:Name 并在此页面中使用VisualStateManager 来调整文本大小,但我在整个应用程序中都使用这些文本样式,我想在某一点更改它们,定义不同屏幕尺寸的字体大小,使用简单的类似 css 的查询:
@media only screen and (min-width: 600px) {
.TextTileH1 {
font-size: 36;
}
}
那么我一般如何在ResourceDirectory 中使用VisualStateManager 来一次更改所有文本样式以适应不同的屏幕尺寸?
我尝试过使用this answer,但根据我的评论我无法成功,我尝试为<StackPanel> 之一应用更大的边距(也给它一个应该的名字) 但没有任何改变。
【问题讨论】:
标签: c# xaml uwp responsive visualstatemanager