TextBlock FontSize适用于不同的分辨率

时间:2019-05-20 05:40:08

标签: c# wpf textblock

我有这样的TextBlock

 <TextBlock HorizontalAlignment="Stretch" 
                               VerticalAlignment="Stretch"
                               Text="{Binding LocationName,UpdateSourceTrigger=PropertyChanged}"
                               FontWeight="Bold" 
                               IsEnabled="False" TextAlignment="Center"
                               Focusable="False">

它显示的是C2,就像图像中显示的一样。如果我设置字体大小,它可以正常工作。但是在不同的分辨率下,我遇到了问题。如何将其设置为适当的大小?

enter image description here

ViewBox

这是我在使用Viewbox时遇到的问题

  <Grid Name="Locationgrid" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"  >
                    <Viewbox>
                        <TextBlock Text="{Binding LocationName,UpdateSourceTrigger=PropertyChanged}"
                                   FontWeight="Bold" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"
                                   IsEnabled="False" TextAlignment="Center"
                                   Focusable="False">
                            <TextBlock.Style>
                                <Style TargetType="{x:Type TextBlock}">
                                    <Style.Triggers>
                                        <DataTrigger Binding="{Binding IsWrongLocationErrorVisible}" Value="Visible">
                                            <Setter Property="Foreground" Value="{DynamicResource WarehouseInValidLocationForeground}"></Setter>
                                            <Setter Property="Background" Value="{DynamicResource WarehouseInValidLocationBackground}"></Setter>
                                        </DataTrigger>
                                        <DataTrigger Binding="{Binding IsWrongLocationErrorVisible}" Value="Collapsed">
                                            <Setter Property="Foreground" Value="{DynamicResource WarehouseValidLocationForeground}"></Setter>
                                            <Setter Property="Background" Value="{DynamicResource WarehouseValidLocationBackground}"></Setter>
                                        </DataTrigger>
                                        <DataTrigger Binding="{Binding IsWrongLocationErrorVisible}" Value="Hidden">
                                            <Setter Property="Foreground" Value="{DynamicResource WarehouseInitialLocationForeground}"></Setter>
                                            <Setter Property="Background" Value="{DynamicResource WarehouseInitialLocationBackground}"></Setter>
                                        </DataTrigger>
                                    </Style.Triggers>
                                </Style>
                            </TextBlock.Style>
                        </TextBlock>
                    </Viewbox>
                </Grid>

enter image description here

0 个答案:

没有答案