views:

142

answers:

2

Hey,

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>
A: 

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>
Sdry
+1  A: 

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.

John Bowen