WPF:如何在调整大小时绘制多边形以保留LineSegments的角度

时间:2011-10-17 13:48:01

标签: wpf resize polygon angle

我创建了一个光滑的面板效果,如下所示:

Glossy panel

这是XAML:

  <Window x:Class="Window1"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      Title="Window1" Height="200" Width="300">
      <StackPanel Orientation="Vertical">
          <StackPanel.Background>
              <DrawingBrush>
                  <DrawingBrush.Drawing>
                      <DrawingGroup>
                          <GeometryDrawing>
                              <GeometryDrawing.Geometry>
                                  <RectangleGeometry Rect="0,0,1,1"></RectangleGeometry>
                              </GeometryDrawing.Geometry>
                              <GeometryDrawing.Brush>
                                  <SolidColorBrush Opacity="0.5" Color="Blue" />
                              </GeometryDrawing.Brush>
                          </GeometryDrawing>
                          <GeometryDrawing>
                              <GeometryDrawing.Geometry>
                                  <PathGeometry>
                                      <PathGeometry.Figures>
                                          <PathFigureCollection>
                                              <PathFigure IsClosed="True" StartPoint="0,0">
                                                  <PathFigure.Segments>
                                                      <PathSegmentCollection>
                                                          <LineSegment Point="0.3,0" />
                                                          <LineSegment Point="0.2,1" />
                                                          <LineSegment Point="0,1" />
                                                          <LineSegment Point="0,0" />
                                                      </PathSegmentCollection>
                                                  </PathFigure.Segments>
                                              </PathFigure>
                                          </PathFigureCollection>
                                      </PathGeometry.Figures>
                                  </PathGeometry>
                              </GeometryDrawing.Geometry>
                              <GeometryDrawing.Brush>
                                  <LinearGradientBrush StartPoint="0,0.5" EndPoint="1,0.5">
                                      <GradientStop Offset="0.0" Color="Transparent" />
                                      <GradientStop Offset="0.7" Color="#58FFFFFF" />
                                      <GradientStop Offset="1.0" Color="#AFFFFFFF" />
                                  </LinearGradientBrush>
                              </GeometryDrawing.Brush>
                          </GeometryDrawing>
                      </DrawingGroup>
                  </DrawingBrush.Drawing>
              </DrawingBrush>
          </StackPanel.Background>
      </StackPanel>
  </Window>

现在,如果我将此窗口调整到一半高度,则闪烁的角度与以前不同:

Resized to half the height

我知道上面的代码应该像这样工作,我的问题是:如何创建相同的效果,以便在调整大小时保留多边形线段的角度?半高调整大小的最终结果是:

Desired resize to half the height: angle of the glint is preserved

1 个答案:

答案 0 :(得分:1)

我认为

    <DrawingBrush Stretch="UniformToFill">
        ...

应该这样做。