There are many buttons with the same style, in which only the icon and the name and toolTip change. How to create a universal style for them?
Here is the style:
<Style TargetType="{x:Type Button}"> <Setter Property="SnapsToDevicePixels" Value="True"/> <Setter Property="VerticalAlignment" Value="Center"/> <Setter Property="HorizontalAlignment" Value="Stretch"/> <Setter Property="Width" Value="200"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type Button}"> <Border Width="{TemplateBinding Width}"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="auto"/> <ColumnDefinition Width="*"/> <ColumnDefinition Width="5"/> </Grid.ColumnDefinitions> <Rectangle Name="Rectagle" Grid.Column="0" Margin="2.5" Height="30" Width="30" Fill="White"> <Rectangle.OpacityMask> <VisualBrush Visual="{TemplateBinding local:MyButtonExtension.Icon}" Stretch="Fill"/> </Rectangle.OpacityMask> </Rectangle> <TextBlock Name="Name" Grid.Column="1" Margin="5" VerticalAlignment="Center" HorizontalAlignment="Stretch" Foreground="White" FontSize="12" Text="{TemplateBinding Content}"/> <Rectangle Name="Flag" Grid.Column="2" Fill="Transparent"/> </Grid> </Border> <ControlTemplate.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter TargetName="Flag" Property="Fill" Value="{StaticResource MainBrush}"/> <Setter TargetName="Rectagle" Property="Fill" Value="{StaticResource MainBrush}"/> <Setter TargetName="Name" Property="Foreground" Value="{StaticResource MainBrush}"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> And here is how I use it:
<Button Content="Создать конфигурацию" Command="{Binding CreateConfig}"> How to correctly implement such a style, with the ability to transfer to the Rectagle (inside the style) OpacityMask, in which there will be an icon.
While the solution I see is the creation of a separate control in which to create a property for the icon, but I think there is a more correct solution.
UPD 1:
Use check:
<Button local:MyButtonExtension.Text="Создать конфигурацию" local:MyButtonExtension.Icon="{StaticResource appbar_newspaper_create}" Command="{Binding CreateConfig}"> </Button> Icon:
<Canvas x:Key="appbar_newspaper_create" Width="76" Height="76" Clip="F1 M 0,0L 76,0L 76,76L 0,76L 0,0"> <Path Width="48.0313" Height="43" Canvas.Left="17" Canvas.Top="14" Stretch="Fill" Fill="{DynamicResource BlackBrush}" Data="(удалил, чтобы не засорять)"/> </Canvas> 
