添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
精彩文章免费看

WPF 使Button字体自适应屏幕大小

使用Viewbox可以拉伸和缩放单个子元素以填满可用空间。
把viewbox直接放在默认格式的button外面

<Viewbox>
   <Button>left</Button>
</Viewbox>
<ControlTemplate x:Key="radiusBtnTemplate" TargetType="Button">
      <Border CornerRadius="48" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}">
          <ContentPresenter Content="{TemplateBinding ContentControl.Content}" HorizontalAlignment="Center" VerticalAlignment="Center" />
      </Border>
</ControlTemplate>
ContentPresenter外加一个TextBlock
<ControlTemplate x:Key="radiusBtnTemplate" TargetType="Button">
    <Border CornerRadius="48" Name="PART_Background" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}">
        <Viewbox>
            <TextBlock Margin="10">
                <ContentPresenter Content="{TemplateBinding ContentControl.Content}" HorizontalAlignment="Center" VerticalAlignment="Center" />
             </TextBlock>
        </Viewbox>
    </Border>
</ControlTemplate>
              禁止转载,