开发者

WPF: How do I draw a Polygon to preserve angles of LineSegments when Resizing

I created a glossy panel effect that looks like this:

WPF: How do I draw a Polygon to preserve angles of LineSegments when Resizing

This is the 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.Figu开发者_Go百科res>
                                  </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>

Now, if I resize this window to half the height, the glint is slanted at a different angle than before:

WPF: How do I draw a Polygon to preserve angles of LineSegments when Resizing

I understand that the code above is supposed to work like this, and my question is: How do I create the same effect such that the angle of the polygon segment is preserved on resize? The desired end result for the half height resize is:

WPF: How do I draw a Polygon to preserve angles of LineSegments when Resizing


I think

    <DrawingBrush Stretch="UniformToFill">
        ...

should do the trick.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜