Simple (I think) Horizontal Line in WPF?

2019-01-16 04:54发布

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.

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?

5条回答
Explosion°爆炸
2楼-- · 2019-01-16 05:30
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>
查看更多
Emotional °昔
3楼-- · 2019-01-16 05:42

For anyone else struggling with this: "Qwertie's" comment above worked well for me.

<Border Width="1" Margin="2" Background="#8888"/>

This creates a vertical seperator whcih you can talior to suit your needs.

查看更多
老娘就宠你
4楼-- · 2019-01-16 05:47

I had the same issue and eventually chose to use a Rectangle element:

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

查看更多
forever°为你锁心
5楼-- · 2019-01-16 05:51

Use a Border of height 1 and don't set the Width (i.e. Width = Auto, HorizontalAlignment = Stretch, the default)

查看更多
Juvenile、少年°
6楼-- · 2019-01-16 05:55

How about add this to your xaml:

<Separator/>
查看更多
登录 后发表回答