开发者

WPF Separator position

开发者 https://www.devze.com 2022-12-28 13:33 出处:网络
I\'m using a Separator to draw a vertical line inside a Border. At first this was ok because the line needed to be centered, but now I need to position it at a custom x-position from the left border.

I'm using a Separator to draw a vertical line inside a Border. At first this was ok because the line needed to be centered, but now I need to position it at a custom x-position from the left border. Is there a way to do that?

<Border x:Name="border" ClipToB开发者_如何学JAVAounds="True" Background="White" BorderBrush="Black" BorderThickness="2">
    <Separator BorderBrush="Black" BorderThickness="2">
        <Separator.LayoutTransform>
            <RotateTransform Angle="90" />
        </Separator.LayoutTransform>
    </Separator>
</Border>


I'm not sure of the proper way, if availble, but if you are not resizing the border, you could use a margin like this:

<Border x:Name="border" ClipToBounds="True" Background="White" BorderBrush="Black" BorderThickness="2">
            <Separator BorderBrush="Black" BorderThickness="2" Height="2"  Margin="0,0,100,0">
                <Separator.LayoutTransform>
                    <RotateTransform Angle="90" />
                </Separator.LayoutTransform>
            </Separator>
        </Border>


The simplest change you can make is just to set the HorizontalAlignment and then use Margins to offset the Separator (the default is 0,2,0,2):

<Border x:Name="border" ClipToBounds="True" Background="White" BorderBrush="Black" BorderThickness="2">
    <Separator BorderBrush="Black" BorderThickness="2" HorizontalAlignment="Left" Margin="20,2,0,2" >
        <Separator.LayoutTransform>
            <RotateTransform Angle="90" />
        </Separator.LayoutTransform>
    </Separator>
</Border>

There are lots of other ways you could achieve the same visual effect if you have other requirements.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号