using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Shapes;
namespace WpfApp1;
[TemplatePart(Name = "PART_Path", Type = typeof(Path))]
public class PathButton : Button
{
public static readonly DependencyProperty PathDataProperty =
DependencyProperty.Register(
nameof(PathData),
typeof(Geometry),
typeof(PathButton),
new PropertyMetadata(null));
public Geometry PathData
{
get => (Geometry)GetValue(PathDataProperty);
set => SetValue(PathDataProperty, value);
}
}
<Style TargetType="{x:Type local:PathButton}">
<Setter Property="Background" Value="Transparent" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:PathButton}">
<Grid>
<Path
x:Name="PART_Path"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Data="{TemplateBinding PathData}"
Fill="{TemplateBinding Foreground}"
Stretch="Uniform" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<local:PathButton
Width="30"
Height="30"
Foreground="DodgerBlue"
PathData="M28.166016,0L32,3.8740238 11.496002,19.745 0,7.9879777 4.4200134,4.6370251 12.070007,12.476016z" />