2017-10-10 135 views
0

我想創建一個不規則形狀的窗口。我做了類似於我最終想要創造的東西,但我想要一些圓角的東西。我在某處讀到PolyLineSegment無法實現,您能否告訴我如何創建它?我應該使用什麼對象/對象集合?如何使PolyLineSegment的角落變圓?

<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
       xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
       xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
       xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
       mc:Ignorable="d" 
       d:DesignHeight="250" d:DesignWidth="400" 
       AllowsTransparency="True" 
       OpacityMask="White" 
       WindowStyle="None" 
       Background="Transparent" 
       > 
     <Canvas> 
     <Path Height="250" 
       Stroke="Gray" 
       StrokeThickness="2" 
       Name="UIPath" 

       > 
      <Path.Fill> 
      <SolidColorBrush Color="Aqua"> 
      </SolidColorBrush> 
      </Path.Fill> 
      <Path.Data> 
      <PathGeometry> 
       <PathFigureCollection> 
       <PathFigure StartPoint="0,0" 
          IsClosed="True"> 
        <PolyLineSegment IsSmoothJoin="True" Points="400,000" /> 

        <PolyLineSegment IsSmoothJoin="True" 
            Points="400,200" /> 
        <PolyLineSegment IsSmoothJoin="True" 
            Points="180,200" /> 

        <PolyLineSegment IsSmoothJoin="True" 
            Points="200,250" /> 
        <PolyLineSegment IsSmoothJoin="True" 
            Points="100,200" /> 

        <PolyLineSegment IsSmoothJoin="True" 
            Points="00,200" /> 

       </PathFigure> 
       </PathFigureCollection> 
      </PathGeometry> 
      </Path.Data> 
      <Path.ContextMenu> 
      <ContextMenu> 
       <MenuItem Header="Minimize" 
         Name="mnuInvokeMinimize" /> 
       <MenuItem Header="Maximize" 
         Name="mnuInvokeMaximize" /> 
       <MenuItem Header="Restore Down" 
         Name="mnuInvokeRestore" /> 
       <MenuItem Header="Close" 
         Name="mnuInvokeClose" /> 
      </ContextMenu> 
      </Path.ContextMenu> 
      <Path.RenderTransform> 
      <TransformGroup x:Name="pathTfg"> 
       <ScaleTransform ScaleX="1" 
           ScaleY="1" /> 
       <TranslateTransform /> 
      </TransformGroup> 
      </Path.RenderTransform> 
     </Path> 
     </Canvas> 
    </Window> 

回答

1

你可以使用一個CombinedGeometryRectangleGeometry圓角和其餘部分PathGeometry

<Path Fill="Aqua" Stroke="Gray" StrokeThickness="2"> 
    <Path.Data> 
     <CombinedGeometry> 
      <CombinedGeometry.Geometry1> 
       <RectangleGeometry Rect="0,0,400,200" RadiusX="20" RadiusY="20"/> 
      </CombinedGeometry.Geometry1> 
      <CombinedGeometry.Geometry2> 
       <PathGeometry Figures="M180,200 L200,250 100,200"/> 
      </CombinedGeometry.Geometry2> 
     </CombinedGeometry> 
    </Path.Data> 
</Path>