简体   繁体   English

当我们在网格 WPF 的右端绘制线条时,线条的 StrokeThickness 无法正常工作

[英]StrokeThickness of Line is not working properly when we draw the line at the right end of the Grid WPF

I am trying to set the StrokeThickness of the line is more than 1. But StrokeThickness is not applied properly in the line which is in the right side of the grid.我正在尝试将线条的 StrokeThickness 设置为大于 1。但是 StrokeThickness 未正确应用在网格右侧的线条中。 left side line is working properly.左侧线工作正常。 Code snippet代码片段

<Grid
        x:Name="BottomRightPanel"
        Width="500"
        HorizontalAlignment="Center"
        VerticalAlignment="Center"
        Background="Yellow">
        <Line
            x:Name="line"
            Stroke="Black"
            StrokeThickness="5"
            X1="0"
            X2="0"
            Y1="0"
            Y2="50" />
        <Line
            x:Name="line1"
            Stroke="Black"
            StrokeThickness="5"
            X1="500"
            X2="500"
            Y1="0"
            Y2="50">
        </Line>
    </Grid>

Screenshot:截屏:

Line is cropped线条被裁剪

Decrease the X1 and X2 values of the right line to take the stroke thickness into consideration:减小右侧线的 X1 和 X2 值以考虑笔划粗细:

<Line
    x:Name="line1"
    Stroke="Black"
    StrokeThickness="5"
    X1="497.5"
    X2="497.5"
    Y1="0"
    Y2="50">

Or use a Border :或使用Border

<Border Width="500" Background="Yellow"
        BorderBrush="Black" BorderThickness="5 0 5 0"
        HorizontalAlignment="Center"
        VerticalAlignment="Center">
    <Grid>
        <TextBlock />
    </Grid>
</Border>

From my observation, you have provided some thickness for a line like 5, even though it has been drawn correctly due to this added thickness it plot like X position of 505.根据我的观察,您已经为像 5 这样的线提供了一些粗细,尽管由于这种增加的粗细而正确绘制了它 plot 就像 X position 为 505。

Better you can adjust the X postion in below更好的是,您可以在下面调整 X 位置

 <Line x:Name="line" Stroke="Black" StrokeThickness="5" X1="0" X2="0" Y1="0" Y2="50" /> <Line x:Name="line1" Stroke="Black" StrokeThickness="5" X1="495" X2="495" Y1="0" Y2="50"/>

Or else add like in below或者像下面这样添加

 <Canvas> <Line x:Name="line" Stroke="Black" StrokeThickness="5" X1="0" X2="0" Y1="0" Y2="50" /> <Line x:Name="line1" Canvas.Left="500" Stroke="Black" StrokeThickness="5" X1="0" X2="0" Y1="0" Y2="50" /> </Canvas>
Keep the same line plot values and move that in left most by using Canvas.Left 保持同一行 plot 值并使用 Canvas.Left 将其移到最左边

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM