本文經過設計一個RadioButton,分享下使用Blend繪製Path的方法。待繪製的RadioButton樣式以下文所示,若有更好的方法實現該樣式,歡迎交流。app
將要實現的RadioButton樣式以下圖,能夠看出按鈕的筆尖和筆身的填充色,以及選中時右上方圓形的填充色一致,表明筆的顏色。工具
筆身使用矩形,填充色綁定按鈕背景色;筆頭部分使用閉合的Path,其中筆尖的顏色一樣綁定按鈕背景色;右上方的圓形使用Ellipse,填充色一樣綁定按鈕背景色。spa
// 最終Style <Style x:Key="RadioButtonStyle1" TargetType="{x:Type RadioButton}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type RadioButton}"> <Grid x:Name="templateRoot" Background="Transparent" SnapsToDevicePixels="True"> <Rectangle Fill="{Binding Background, RelativeSource={RelativeSource TemplatedParent}}" HorizontalAlignment="Center" Height="37" Stroke="Black" VerticalAlignment="Bottom" Width="23.5" Margin="13,0"/> <Path Data="M16.4,0.76 L7.4,0.76 M7.7,0.7 C2,12.87 0.5,24.1 0.5,24.1 0.5,24.1 23.1,23.8 23.1,23.8 23.1,23.8 20.7,6.5 16,0.5" HorizontalAlignment="Center" Height="24.6" Stretch="Fill" Stroke="Black" VerticalAlignment="Top" Width="23.6" Margin="13,19.4,13,0"> <Path.Fill> <LinearGradientBrush EndPoint="0.5,0.5" MappingMode="RelativeToBoundingBox" StartPoint="0,0.5" SpreadMethod="Reflect"> <GradientStop Color="#FF626060"/> <GradientStop Color="#FFD6D3D3" Offset="0.873"/> </LinearGradientBrush> </Path.Fill> </Path> <Path Data="M21.1,19.3 C21.1,19.3 25.3,-5.5 28.2,19.2" Fill="{Binding Background, RelativeSource={RelativeSource TemplatedParent}}" HorizontalAlignment="Left" Height="12" Margin="21.2,8.3,0,0" Stretch="Fill" Stroke="Black" VerticalAlignment="Top" Width="8"/> <Ellipse Fill="{Binding Background, RelativeSource={RelativeSource TemplatedParent}}" HorizontalAlignment="Right" Height="3" Stroke="Black" VerticalAlignment="Top" Width="3" Margin="0,3,3,0" StrokeThickness="0"/> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style>
使用Blend繪製Path的方法參考官網。設計
Path由一系列的直線或曲線鏈接而成,能夠使用Line、Pen、Pencil工具繪製Path,能夠在工具條中找到它們。3d
使用Pen工具,點擊添加曲線起點,再次點擊並拖動能夠添加點並調整兩點間的曲線形狀。若想閉合Path,點擊起點便可。code
使用路徑選擇工具,選中形狀,拖動曲線上的點以改變形狀。blog
使用路徑選擇工具,選中Path上要刪除的線段,點擊刪除按鈕。ip
使用選擇工具選中Path,使用Pen工具點擊Path上的點便可刪除。ci
使用選擇工具選中Path,使用Pen工具在想要添加點的位置點擊。資源
使用Pencil工具進行繪製。