J'ai WPF Form qui a beaucoup de boutons avec le même code. Apparence de tous les boutons doivent être identiques Par exemple, le code pour un de ces boutonsWPF Boutons Style
<Button x:Name="btnAddRelative" Width="120" Click="btnAddRelative_Click" >
<Button.Content>
<StackPanel Orientation="Horizontal">
<Image Height="26" HorizontalAlignment="Left">
<Image.Source>
<BitmapImage UriSource="images/add.png" />
</Image.Source>
</Image>
<TextBlock Text=" Add Relative" Height="20" VerticalAlignment="Center"/>
</StackPanel>
</Button.Content>
</Button>
Comment puis-je créer un style et l'utiliser pour tous mes boutons. Tous les boutons ont la même image png, seul leur texte est différent. Comment puis-je faire ceci. J'ai essayé de le faire avec un objet Style dans la section des ressources:
<UserControl.Resources>
<Style TargetType="Button" x:Key="AddStyle">
<Setter Property="Content">
<Setter.Value>
<StackPanel Orientation="Horizontal">
<Image Height="26" HorizontalAlignment="Left">
<Image.Source>
<BitmapImage UriSource="images/add.png" />
</Image.Source>
</Image>
<TextBlock Text=" " Height="20" VerticalAlignment="Center"/>
</StackPanel>
</Setter.Value>
</Setter>
</Style>
</UserControl.Resources>
Mais ce code fonctionne pas. Quelqu'un peut-il savoir comment puis-je faire cela?
Merci beaucoup. Super personnel. Ca marche comme je veux !!!! – Polaris