【问题标题】:Why is WPF PathFigure not filled at certain rotations?为什么 WPF PathFigure 在某些旋转时未填充?
【发布时间】:2019-04-05 12:45:32
【问题描述】:

箭头应该有红色填充,但在 RotateTransform 的某些角度缺少填充。它从 ~92° 消失到 ~279°

在我的完整项目中,也出现了只有箭头的一部分被填充的情况。这是 WPF 渲染错误还是我在这里做错了什么?

  <StackPanel Orientation="Vertical">

    <Slider x:Name="slider"
            Value="180"
            Minimum="0"
            Maximum="360" />

    <Canvas Width="296"
            Height="296">
      <Canvas.Background>
        <DrawingBrush Stretch="Uniform">
          <DrawingBrush.Drawing>
            <DrawingGroup>
              <GeometryDrawing Brush="Red">
                <GeometryDrawing.Pen>
                  <Pen Brush="Lime"
                       Thickness="2" />
                </GeometryDrawing.Pen>
                <GeometryDrawing.Geometry>
                  <PathGeometry>
                    <PathGeometry.Transform>
                      <TransformGroup>
                        <RotateTransform Angle="{Binding ElementName=slider, Path=Value}" />
                      </TransformGroup>
                    </PathGeometry.Transform>
                    <PathGeometry.Figures>
                      <PathFigure IsClosed="True"
                                  StartPoint="100 50">
                        <LineSegment Point="50 87.5" />
                        <LineSegment Point="50 62.5" />
                        <LineSegment Point=" 0 62.5" />
                        <LineSegment Point=" 0 37.5" />
                        <LineSegment Point="50 37.5" />
                        <LineSegment Point="50 12.5" />
                      </PathFigure>
                    </PathGeometry.Figures>
                  </PathGeometry>
                </GeometryDrawing.Geometry>
              </GeometryDrawing>
            </DrawingGroup>
          </DrawingBrush.Drawing>
        </DrawingBrush>
      </Canvas.Background>
    </Canvas>
  </StackPanel>

【问题讨论】:

    标签: wpf rendering


    【解决方案1】:

    您可以简单地通过其 RenderTransform 旋转路径:

    <Path Width="296" Height="296" Stretch="Uniform"
          Fill="Red" Stroke="Lime" StrokeThickness="8"
          Data="M100,50 L50,87.5 50,62.5 0,62.5 0,37.5 50,37.5 50,12.5Z"
          RenderTransformOrigin="0.5,0.5">
        <Path.RenderTransform>
            <RotateTransform Angle="{Binding ElementName=slider, Path=Value}" />
        </Path.RenderTransform>
    </Path>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-31
      • 2015-11-24
      • 2021-01-20
      相关资源
      最近更新 更多