WPF组框头现在的位置对齐 [英] WPF Groupbox header postion alignment

查看:223
本文介绍了WPF组框头现在的位置对齐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能设置在WPF为分组框 标题对位?默认值是在分组框轮廓的左上角的地方,但我想它在顶部居中。我知道,你可以使用设置文本的属性:

Is it possible to set the position alignment for a GroupBox Header in WPF? The default is to place in the top left corner of the GroupBox outline but I would like it to be centered at the top. I know that you can set the properties of the text using:

<GroupBox Grid.Row="1" HorizontalAlignment="Center">
   <GroupBox.Header> 
      <TextBlock Text="Cash Match" Foreground="Black" FontWeight="Bold"/>
   </GroupBox.Header>
</GroupBox>

但我希望设置它的位置相对于在分组框轮廓。

推荐答案

这很简单!只要编辑组框模板:

It's simple! Just edit Template of GroupBox:

在Blend中,请执行以下操作:

In Blend, do the following :

  • 右键点击分组框>编辑模板>编辑复制>确定
  • 搜索以下部分:

  • Right click GroupBox > Edit Template > Edit a Copy > OK
  • Search for following section:

<Border x:Name="Header" Padding="3,1,3,0" 
        Grid.Column="1" Grid.Row="0" Grid.RowSpan="2">
    ...
</Border>

  • 修改 Grid.Column 2

    您刚才对准头向右!但BOT背后的白色差距。为此,

    You have just aligned the header to right!!! But bot the white gap behind it. For that,

    • 现在搜索以下部分:

    • Now search for following section :

    <Border BorderBrush="White" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="4" Grid.ColumnSpan="4" Grid.Row="1" Grid.RowSpan="3">
        <Border.OpacityMask>
            ...
        </Border.OpacityMask>
        ...
    </Border>
    

  • 添加 RenderTransformOrigin =0.5,0.5边境

    正上方,添加以下code(这将移位的白差距的背后头向右:

    Just above , add following code (this will shift the "white gap" behind header to right:

    <Border.RenderTransform>
        <ScaleTransform ScaleX="-1"/>
    </Border.RenderTransform>
    

  • 您完成了!你刚刚右对齐的头!

    You are done! You just got a GroupBox with right aligned header!!!

    请告诉我,如果这是你所需要的东西。

    Please tell me if this is what you required.

    这篇关于WPF组框头现在的位置对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆