Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF Separator position

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" ClipToBounds="True" Background="White" BorderBrush="Black" BorderThickness="2">
    <Separator BorderBrush="Black" BorderThickness="2">
        <Separator.LayoutTransform>
            <RotateTransform Angle="90" />
        </Separator.LayoutTransform>
    </Separator>
</Border>
like image 381
morsanu Avatar asked Apr 30 '10 13:04

morsanu


2 Answers

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>
like image 54
Samuel DR Avatar answered Oct 21 '22 02:10

Samuel DR


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.

like image 36
John Bowen Avatar answered Oct 21 '22 01:10

John Bowen