WPF XAML中边框各边的颜色不同?

时间:2012-03-28 17:39:21

标签: wpf xaml

我想在WPF XAML中为边框的每一边添加不同的颜色。我怎么能这样做。

<Border BorderThickness="1,2,3,4" BorderBrush="Blue"></Border>

3 个答案:

答案 0 :(得分:4)

有点hacky,但它确实有效。

<Grid>
    <Border BorderThickness="1,0,0,0" BorderBrush="Blue"/>
    <Border BorderThickness="0,2,0,0" BorderBrush="Red"/>
    <Border BorderThickness="0,0,3,0" BorderBrush="Green"/>
    <Border BorderThickness="0,0,0,4" BorderBrush="Orange"/>
</Grid>

创建自己的Decorator可能会更好。

答案 1 :(得分:4)

也许?

    <DockPanel LastChildFill="True">
        <Rectangle Fill="Red" DockPanel.Dock="Top" Height="2"/>
        <Rectangle Fill="Yellow" DockPanel.Dock="Left" Width="2"/>
        <Rectangle Fill="Green" DockPanel.Dock="Right" Width="2"/>
        <Rectangle Fill="Blue" DockPanel.Dock="Bottom" Height="2"/>
        <Rectangle Fill="Wheat"/>
    </DockPanel>

答案 2 :(得分:0)

使用四个边框https://stackoverflow.com/a/1797045/5229294

有一种hacky方式
<Border BorderThickness="0,0,0,10" BorderBrush="Green">
    <Border BorderThickness="0,0,10,0" BorderBrush="Blue">
        <Grid>
            <Button>Hello</Button>
        </Grid>
    </Border>
</Border>