【问题标题】:WPF Border thickness bottom only..WPF 边框厚度仅底部..
【发布时间】:2014-04-24 10:48:06
【问题描述】:

我正在尝试创建底部只有边框的 WPF 按钮,其余的将隐藏。我尝试使用borderthickness =“0,0,0,1”但它不起作用..这是我的代码..

<Button Background="Transparent" BorderThickness="0,0,0,1" BorderBrush="Transparent"  Width="235" Padding="5" FlowDirection="LeftToRight">
<StackPanel Orientation="Horizontal" Width="260">
<Image Source="Images/room-32.png" Height="20" Margin="30,0,8,0"/>
<TextBlock Width="200">Station Maintenance</TextBlock>
</StackPanel>
</Button>

【问题讨论】:

    标签: wpf xaml button


    【解决方案1】:

    这是因为BorderBrush 设置为Transparent。为其指定颜色。

    <Button Background="Transparent" BorderThickness="0,0,0,1" BorderBrush="Black"  Width="235" Padding="5" FlowDirection="LeftToRight">
       <StackPanel Orientation="Horizontal" Width="260">
          <Image Source="Images/room-32.png" Height="20" Margin="30,0,8,0"/>
          <TextBlock Width="200">Station Maintenance</TextBlock>
       </StackPanel>
    </Button>
    

    所以,而不是

    BorderBrush="Transparent"
    

    使用

    BorderBrush="Black" // Any color you would like
    

    编辑

    如果您想在 button 周围添加一个边框,甚至在 hover 等上可见...而不是在您的 button 周围添加 border element

      <Border BorderBrush="Black" BorderThickness="0,0,0,1">
          <Button Background="Transparent"
                  Width="235"
                  Padding="5"
                  FlowDirection="LeftToRight">
              <StackPanel Orientation="Horizontal"
                          Width="260">
                   <Image Source="Images/room-32.png"
                         Height="20"
                         Margin="30,0,8,0" />
                   <TextBlock Width="200">Station Maintenance</TextBlock>
              </StackPanel>
          </Button>
      </Border>
    

    【讨论】:

    • 我以这种方式尝试 Loetn 但是,除了底部有边框之外,它也会触发另一部分。我不知道问题是什么。感谢您的快速回复。
    • @eiv “它也会触发另一部分”是什么意思?我做了修改,这是你想要的吗?
    • @eiv 您是否以与我不同的方式解决了它?如果是,您是否可以考虑将您的解决方案添加为答案,以便其他人知道您是如何解决的。
    • 不,Loetn,我使用您的解决方案做到了。非常感谢您的帮助。
    猜你喜欢
    • 2011-11-06
    • 1970-01-01
    • 1970-01-01
    • 2013-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-05
    • 1970-01-01
    相关资源
    最近更新 更多