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