WPF边框厚度仅限底部..

时间:2014-04-24 10:48:06

标签: wpf xaml button

我正在尝试创建只有底部边框的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>

1 个答案:

答案 0 :(得分:4)

这是因为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上显示,等等...而不是在border element周围添加button

  <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>