C# 同一类型按钮的模板,但图像不同
我有这个按钮C# 同一类型按钮的模板,但图像不同,c#,wpf,xaml,C#,Wpf,Xaml,我有这个按钮 <Button Width="120" Height="60" HorizontalAlignment="Left" Command="{Binding OpenTimerSettingsWindowCommand}" Style="{StaticResourceGreyButtonStyle}"> <StackPanel Orientation="Horizontal">
<Button
Width="120"
Height="60"
HorizontalAlignment="Left"
Command="{Binding OpenTimerSettingsWindowCommand}"
Style="{StaticResourceGreyButtonStyle}">
<StackPanel
Orientation="Horizontal">
<Rectangle
Width="25"
Height="25">
<Rectangle.Fill>
<VisualBrushStretch="Uniform"
Visual="{StaticResource appbar_timer}"/>
</Rectangle.Fill>
</Rectangle>
<TextBlock
Margin="5,0,0,0"
VerticalAlignment="Center"
FontSize="14"
Foreground="White"
Text="Timers"/>
</StackPanel>
</Button>
实际上,我有很多这样的按钮——但只有一个和两个小的例外;
命令和矩形内的“可视”按钮
我的问题:
有没有办法在app.xaml中指定一次并在my window.xaml中绑定Visual?还是每次我有一个按钮时都要粘贴这个?
我倾向于创建自己的控件,但我想知道是否可以为此创建一个数据模板请参阅我的上一篇文章,可能会有所帮助。为了设置不同的图像,请创建附加的依赖项属性并将其绑定到模板中。