wpf WPF中的简单(我认为)水平线?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2314975/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Simple (I think) Horizontal Line in WPF?
提问by Phil Sandler
Creating a relatively simple data entry form, and just want to separate certain sections with a horizontal line (not unlike an HR tag in HTML) that stretches the full length of the form.
创建一个相对简单的数据输入表单,并且只想用一条水平线(与 HTML 中的 HR 标记不同)分隔某些部分,该线延伸表单的整个长度。
I have tried this:
我试过这个:
<Line Stretch="Fill" Stroke="Black" X2="1"/>
Because the parent control is not a fixed width, this line causes the window to stretch to the full width of the screen.
因为父控件的宽度不是固定的,所以这条线会导致窗口拉伸到屏幕的整个宽度。
Is there an easy way to do this without fixing the width of my parent control/window?
有没有一种简单的方法可以在不固定父控件/窗口的宽度的情况下做到这一点?
回答by Adel Hazzah
How about add this to your xaml:
将它添加到您的 xaml 怎么样:
<Separator/>
回答by Deruijter
I had the same issue and eventually chose to use a Rectangle element:
我遇到了同样的问题,最终选择使用 Rectangle 元素:
<Rectangle HorizontalAlignment="Stretch" Fill="Blue" Height="4"/>
<Rectangle HorizontalAlignment="Stretch" Fill="Blue" Height="4"/>
In my opinion it's somewhat easier to modify/shape than a separator.
Of course the Separator
is a very easy and neat solution for simple separations :)
在我看来,修改/形状比分隔符更容易。当然,Separator
对于简单的分离,这是一个非常简单和整洁的解决方案:)
回答by Ana Betts
Use a Border of height 1 and don't set the Width (i.e. Width = Auto, HorizontalAlignment = Stretch, the default)
使用高度为 1 的边框,不设置宽度(即 Width = Auto,HorizontalAlignment = Stretch,默认)
回答by P_Fitz
For anyone else struggling with this: Qwertie's commentworked well for me.
对于其他为此苦苦挣扎的人:Qwertie 的评论对我来说效果很好。
<Border Width="1" Margin="2" Background="#8888"/>
This creates a vertical seperator whcih you can talior to suit your needs.
这将创建一个垂直分隔符,您可以根据自己的需要进行调整。
回答by shaiju mathew
To draw Horizontal
************************
<Rectangle HorizontalAlignment="Stretch" VerticalAlignment="Center" Fill="DarkCyan" Height="4"/>
To draw vertical
*******************
<Rectangle HorizontalAlignment="Stretch" VerticalAlignment="Center" Fill="DarkCyan" Height="4" Width="Auto" >
<Rectangle.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform Angle="90"/>
<TranslateTransform/>
</TransformGroup>
</Rectangle.RenderTransform>
</Rectangle>