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>
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With