xaml styles 有没有办法将 fontsize 指定为 5 个值之一?
xaml styles Is there a way to specify fontsize to one of 5 values?
我希望能够支持 5 种尺寸,
非常小,小,正常,大,非常大。
有没有一种巧妙的方式来处理样式?
我在哪里定义小?
- 我知道我可以只写 18,但我可能想稍后再缩放字体...
这是 .Net 5 的完整示例,其中资源位于 MainWindow 中。
<Window x:Class="WpfNet5.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfNet5"
xmlns:system="clr-namespace:System;assembly=System.Runtime"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Window.Resources>
<system:Double x:Key="VerySmall">12</system:Double>
<system:Double x:Key="Small">18</system:Double>
<system:Double x:Key="Medium">22</system:Double>
<system:Double x:Key="Large">26</system:Double>
</Window.Resources>
<Grid>
<StackPanel >
<TextBlock Text="Very small" FontSize="{DynamicResource VerySmall}"/>
<TextBlock Text="Small" FontSize="{DynamicResource Small}"/>
<TextBlock Text="Medium" FontSize="{DynamicResource Medium}"/>
<TextBlock Text="Large" FontSize="{DynamicResource Large}"/>
</StackPanel>
</Grid>
</Window>
运行 时代的情况:
我希望能够支持 5 种尺寸, 非常小,小,正常,大,非常大。
有没有一种巧妙的方式来处理样式?
我在哪里定义小?
- 我知道我可以只写 18,但我可能想稍后再缩放字体...
这是 .Net 5 的完整示例,其中资源位于 MainWindow 中。
<Window x:Class="WpfNet5.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfNet5"
xmlns:system="clr-namespace:System;assembly=System.Runtime"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Window.Resources>
<system:Double x:Key="VerySmall">12</system:Double>
<system:Double x:Key="Small">18</system:Double>
<system:Double x:Key="Medium">22</system:Double>
<system:Double x:Key="Large">26</system:Double>
</Window.Resources>
<Grid>
<StackPanel >
<TextBlock Text="Very small" FontSize="{DynamicResource VerySmall}"/>
<TextBlock Text="Small" FontSize="{DynamicResource Small}"/>
<TextBlock Text="Medium" FontSize="{DynamicResource Medium}"/>
<TextBlock Text="Large" FontSize="{DynamicResource Large}"/>
</StackPanel>
</Grid>
</Window>
运行 时代的情况: