我正在尝试创建底部只有边框的 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>
最佳答案
这是因为 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 元素
按钮
。
<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>
关于WPF 边框厚度仅底部..,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23266723/