WPF Separator position

北慕城南 提交于 2019-12-23 09:42:09

问题


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>

回答1:


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>



回答2:


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.



来源:https://stackoverflow.com/questions/2744627/wpf-separator-position

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!