WPF XAML在元素之间显示一些空格

时间:2015-11-16 18:54:06

标签: wpf xaml

我有这个XAML,只有很少的简单元素,它们应该彼此相邻,没有任何空格。但是,它们之间会显示一些行。总共显示2条线(较粗的线),另外2条(非常薄的线) - 有时,在水平或垂直滚动​​整个工作区时。我相信,后者是由渲染选项引起的,但只有当XAML元素没有设置其大小时才会发生这种情况。在我的情况下 - 每个元素都设置了它的大小。为什么会出现那些更粗更细的线条?如何删除它们?

    <Grid HorizontalAlignment="Left" VerticalAlignment="Top" Background="{x:Null}" SnapsToDevicePixels="True">

        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="100"/>
        </Grid.RowDefinitions>

        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="100"/>
        </Grid.ColumnDefinitions>

        <Rectangle Grid.Row="3" Grid.Column="0" SnapsToDevicePixels="True"
                   HorizontalAlignment="Left"
                   StrokeThickness="0" Stroke="{x:Null}" Fill="Green"
                   Height="100" Width="10">
        </Rectangle>

        <Rectangle Grid.Row="3" Grid.Column="1" SnapsToDevicePixels="True"
                   HorizontalAlignment="Left"
                   StrokeThickness="0" Stroke="{x:Null}" Fill="White"
                   Height="100" Width="10">
        </Rectangle>

        <Rectangle Grid.Row="3" Grid.Column="2" SnapsToDevicePixels="True"
                   HorizontalAlignment="Left"
                   StrokeThickness="0" Stroke="{x:Null}" Fill="Green"
                   Height="100" Width="30">
        </Rectangle>

        <Rectangle Grid.Row="0" Grid.Column="3" SnapsToDevicePixels="True"
                   VerticalAlignment="Top"
                   StrokeThickness="0" Stroke="{x:Null}" Fill="Green"
                   Height="10" Width="100">
        </Rectangle>

        <Rectangle Grid.Row="1" Grid.Column="3" SnapsToDevicePixels="True"
                   VerticalAlignment="Top"
                   StrokeThickness="0" Stroke="{x:Null}" Fill="White"
                   Height="10" Width="100">
        </Rectangle>

        <Rectangle Grid.Row="2" Grid.Column="3" SnapsToDevicePixels="True"
                   VerticalAlignment="Top"
                   StrokeThickness="0" Stroke="{x:Null}" Fill="Green"
                   Height="30" Width="100">
        </Rectangle>

        <Rectangle Grid.Row="3" Grid.Column="3" SnapsToDevicePixels="True"
                   VerticalAlignment="Top"
                   Width="100" Height="100"
                   StrokeThickness="0" Stroke="{x:Null}" Fill="Green">
        </Rectangle>

        <Grid Grid.Row="0" Grid.Column="0" Grid.RowSpan="3" Grid.ColumnSpan="3" SnapsToDevicePixels="True"
              VerticalAlignment="Bottom" HorizontalAlignment="Right"
              Width="50" Height="50"
              Margin="0,0,0,0">
            <Grid.Clip>
                <RectangleGeometry x:Name="CanvasCornerLeftTop0_ClipRect" Rect="0,0 50,50">
                </RectangleGeometry>
            </Grid.Clip>
            <Ellipse VerticalAlignment="Top" HorizontalAlignment="Left" SnapsToDevicePixels="True"
                     StrokeThickness="0" Stroke="{x:Null}" Fill="Green"
                     Height="100" Width="100">
            </Ellipse>
            <Rectangle VerticalAlignment="Top" HorizontalAlignment="Left" SnapsToDevicePixels="True"
                       StrokeThickness="0" Stroke="{x:Null}" Fill="Green"
                       Height="100" Width="100"
                       Visibility="Collapsed">
            </Rectangle>
        </Grid>

        <Grid Grid.Row="1" Grid.Column="1" Grid.RowSpan="2" Grid.ColumnSpan="2" SnapsToDevicePixels="True"
              VerticalAlignment="Bottom" HorizontalAlignment="Right"
              Width="40" Height="40"
              Margin="0,0,0,0">
            <Grid.Clip>
                <RectangleGeometry x:Name="CanvasCornerLeftTop1_ClipRect" Rect="0,0 40,40">
                </RectangleGeometry>
            </Grid.Clip>
            <Ellipse VerticalAlignment="Top" HorizontalAlignment="Left" SnapsToDevicePixels="True"
                     StrokeThickness="0" Stroke="{x:Null}" Fill="White"
                     Height="80" Width="80">
            </Ellipse>
            <Rectangle VerticalAlignment="Top" HorizontalAlignment="Left" SnapsToDevicePixels="True"
                       StrokeThickness="0" Stroke="{x:Null}" Fill="White"
                       Height="80" Width="80"
                       Visibility="Collapsed">
            </Rectangle>
        </Grid>

        <Grid Grid.Row="2" Grid.Column="2" Grid.RowSpan="1" Grid.ColumnSpan="1" SnapsToDevicePixels="True"
              VerticalAlignment="Bottom" HorizontalAlignment="Right"
              Width="30" Height="30"
              Margin="0,0,0,0">
            <Grid.Clip>
                <RectangleGeometry x:Name="CanvasCornerLeftTop2_ClipRect" Rect="0,0 30,30">
                </RectangleGeometry>
            </Grid.Clip>
            <Ellipse VerticalAlignment="Top" HorizontalAlignment="Left" SnapsToDevicePixels="True"
                     StrokeThickness="0" Stroke="{x:Null}" Fill="Green"
                     Height="60" Width="60">
            </Ellipse>
            <Rectangle VerticalAlignment="Top" HorizontalAlignment="Left" SnapsToDevicePixels="True"
                       StrokeThickness="0" Stroke="{x:Null}" Fill="Green"
                       Height="60" Width="60"
                       Visibility="Collapsed">
            </Rectangle>
        </Grid>

    </Grid>

*更新* Hadn用白线解决了这个问题,我只是重新制作了XAML元素并使用了PathFigure而不是Ellipses。现在没有显示任何人工制品:

<Grid HorizontalAlignment="Left" Background="White" VerticalAlignment="Top" SnapsToDevicePixels="True">

    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="100"/>
    </Grid.RowDefinitions>

    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto"/>
        <ColumnDefinition Width="Auto"/>
        <ColumnDefinition Width="Auto"/>
        <ColumnDefinition Width="100"/>
    </Grid.ColumnDefinitions>

    <Rectangle Grid.Row="3" Grid.Column="0" SnapsToDevicePixels="True"
                HorizontalAlignment="Left"
                StrokeThickness="0" Stroke="{x:Null}" Fill="Green"
                Height="100" Width="10">
    </Rectangle>

    <Rectangle Grid.Row="3" Grid.Column="1" SnapsToDevicePixels="True"
                HorizontalAlignment="Left"
                StrokeThickness="0" Stroke="{x:Null}" Fill="White"
                Height="100" Width="10">
    </Rectangle>

    <Rectangle Grid.Row="3" Grid.Column="2" SnapsToDevicePixels="True"
                HorizontalAlignment="Left"
                StrokeThickness="0" Stroke="{x:Null}" Fill="Green"
                Height="100" Width="30">
    </Rectangle>

    <Rectangle Grid.Row="0" Grid.Column="3" SnapsToDevicePixels="True"
                VerticalAlignment="Top"
                StrokeThickness="0" Stroke="{x:Null}" Fill="Green"
                Height="10" Width="100">
    </Rectangle>

    <Rectangle Grid.Row="1" Grid.Column="3" SnapsToDevicePixels="True"
                VerticalAlignment="Top"
                StrokeThickness="0" Stroke="{x:Null}" Fill="White"
                Height="10" Width="100">
    </Rectangle>

    <Rectangle Grid.Row="2" Grid.Column="3" SnapsToDevicePixels="True"
                VerticalAlignment="Top"
                StrokeThickness="0" Stroke="{x:Null}" Fill="Green"
                Height="30" Width="100">
    </Rectangle>

    <Rectangle Grid.Row="3" Grid.Column="3" SnapsToDevicePixels="True"
                VerticalAlignment="Top"
                Width="100" Height="100"
                StrokeThickness="0" Stroke="{x:Null}" Fill="Green">
    </Rectangle>

    <Grid Grid.Row="0" Grid.Column="0" Grid.RowSpan="3" Grid.ColumnSpan="3" SnapsToDevicePixels="True">
        <Path Stretch="Uniform" Fill="Green">
            <Path.Data>
                <PathGeometry>
                    <PathFigure StartPoint="1,0">
                        <LineSegment Point="1,1"/>
                        <LineSegment Point="0,1"/>
                        <ArcSegment Point="1,0" Size="1,1" IsLargeArc="False" SweepDirection="Clockwise"/>
                    </PathFigure>
                </PathGeometry>
            </Path.Data>
        </Path>

        <Rectangle VerticalAlignment="Top" HorizontalAlignment="Left" SnapsToDevicePixels="True"
                    Fill="Green"
                    Visibility="Collapsed">
        </Rectangle>
    </Grid>

    <Grid Grid.Row="1" Grid.Column="1" Grid.RowSpan="2" Grid.ColumnSpan="2" SnapsToDevicePixels="True">
        <Path Stretch="Uniform" Fill="White">
            <Path.Data>
                <PathGeometry>
                    <PathFigure StartPoint="1,0">
                        <LineSegment Point="1,1"/>
                        <LineSegment Point="0,1"/>
                        <ArcSegment Point="1,0" Size="1,1" IsLargeArc="False" SweepDirection="Clockwise"/>
                    </PathFigure>
                </PathGeometry>
            </Path.Data>
        </Path>

        <Rectangle VerticalAlignment="Top" HorizontalAlignment="Left" SnapsToDevicePixels="True"
                    Fill="White"
                    Visibility="Collapsed">
        </Rectangle>
    </Grid>

    <Grid Grid.Row="2" Grid.Column="2" Grid.RowSpan="1" Grid.ColumnSpan="1" SnapsToDevicePixels="True">
        <Path Stretch="Uniform" Fill="Green">
            <Path.Data>
                <PathGeometry>
                    <PathFigure StartPoint="1,0">
                        <LineSegment Point="1,1"/>
                        <LineSegment Point="0,1"/>
                        <ArcSegment Point="1,0" Size="1,1" IsLargeArc="False" SweepDirection="Clockwise"/>
                    </PathFigure>
                </PathGeometry>
            </Path.Data>
        </Path>

        <Rectangle VerticalAlignment="Top" HorizontalAlignment="Left" SnapsToDevicePixels="True"
                    Fill="Green"
                    Visibility="Collapsed">
        </Rectangle>
    </Grid>

</Grid>

截图: enter image description here

0 个答案:

没有答案