WPF 分隔符位置

发布于 2024-08-31 01:34:48 字数 449 浏览 5 评论 0原文

我正在使用分隔符在边框内绘制一条垂直线。起初这没问题,因为线条需要居中,但现在我需要将其定位在距左边框的自定义 x 位置。有办法做到这一点吗?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

二货你真萌 2024-09-07 01:34:48

我不确定正确的方法(如果可用),但如果您不调整边框大小,则可以使用如下边距:

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

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>
心在旅行 2024-09-07 01:34:48

您可以进行的最简单的更改就是设置 Horizo​​ntalAlignment,然后使用边距来偏移分隔符(默认值为 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>

如果您有其他方法,还有很多其他方法可以实现相同的视觉效果要求。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文