WPF常用技巧汇总

发布于:2025-04-19 ⋅ 阅读:(74) ⋅ 点赞:(0)

主要用于记录工作中发现的一些问题和常见的解决方法。

此文会持续更新。

>abp new Evan.MyWpfApp -t wpf --old --framework .net8

1. 解决不同屏幕分辨率下的锯齿问题

UseLayoutRounding="True"

  <Grid UseLayoutRounding="True">
      <Border Margin="10" Width="175" Height="Auto" BorderThickness="10" BorderBrush="Black" CornerRadius="5">
          <Grid>
              <Grid.RowDefinitions>
                  <RowDefinition></RowDefinition>
              </Grid.RowDefinitions>
              <Button Content="156"></Button>
          </Grid>
      </Border>
  </Grid>

2. 解决小尺寸文本模糊的问题FontSize小于


            <StackPanel>
                <TextBlock FontSize="12" Margin="5">This is a Test. Ideal text is blurry at small size.</TextBlock>
                <!--利用GDI渲染小文本-->
                <TextBlock FontSize="12" Margin="5" TextOptions.TextFormattingMode="Display">This is a Test. Ideal text is blurry at small size.</TextBlock>
            </StackPanel>

3. 增加快捷键

            <StackPanel>
                <!--按下Alt+A,txtA会自动获取焦点. lblA的内容: A下面会显示下划线-->
                <Label x:Name="lblA" Content="Choose _A" Target="{Binding ElementName=txtA}"></Label>
                <TextBox x:Name="txtA" Width="150"></TextBox>

                <!--按下Alt+B,txtB会自动获取焦点。lblB的内容: B下面不会显示下划线,下划线显示在B前面-->
                <Label x:Name="lblB" Content="Choose __B" Target="{Binding ElementName=txtB}"></Label>
                <TextBox x:Name="txtB" Width="150"></TextBox>
            </StackPanel>


网站公告

今日签到

点亮在社区的每一天
去签到