有什么方法可以影响 xaml 图标的样式吗?

Is there any way to affect xaml Icons with style?

我已经使用资源字典在我的 WPF 应用程序中包含 xaml 图标,并且我正在使用 ContentControl 在 window 上呈现资源图标。

<MenuItem.Header>
       <StackPanel Orientation="Horizontal">
              <ContentControl Content="{StaticResource appbar_database}" />
       </StackPanel>
</MenuItem.Header>

现在,如何将样式应用于 ContentControl 内的图标?例如将宽度设置为 24px.

编辑 1

这是我的资源字典的样子:

<ControlTemplate x:Key="appbar_database">
    <Canvas xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Width="76" Height="76" Clip="F1 M 0,0L 76,0L 76,76L 0,76L 0,0">
        <Path Width="34" Height="38" Canvas.Left="21" Canvas.Top="19" Stretch="Fill" Fill="#FF000000" Data="F1 M 38,19C 47.3888,19 55,21.0147 55,23.5038L 55,25.5C 55,27.9853 47.3888,30 38,30C 28.6112,30 21,27.9853 21,25.5L 21,23.5C 21,21.0147 28.6112,19 38,19 Z M 55,52.5C 55,54.9853 47.3888,57 38,57C 28.6112,57 21,54.9853 21,52.5L 21,46.5C 21,48.9853 28.6112,51 38,51C 47.384,51 54.9921,48.9874 55,46.5039L 55,52.5 Z M 55,43.5C 55,45.9853 47.3888,48 38,48C 28.6112,48 21,45.9853 21,43.5L 21,37.5C 21,39.9853 28.6112,42 38,42C 47.384,42 54.9921,39.9874 55,37.5038L 55,43.5 Z M 55,34.5C 55,36.9853 47.3888,39 38,39C 28.6112,39 21,36.9853 21,34.5L 21,28.5C 21,30.9853 28.6112,33 38,33C 47.384,33 54.9921,30.9874 55,28.5038L 55,34.5 Z "/>
    </Canvas>
</ControlTemplate>

查看之前的相关回答here。唯一的区别是您要将这些属性绑定到模板,以便您可以在实例中影响它们。

例如,如果您添加一个;

<Setter Property="Width" Value="34"/>

添加到模板中,以便为该模板建立默认值 属性,然后在模板内的路径中将其更改为;

Width="{TemplateBinding Width}"

然后...在实例级别,您可以放置​​;

<ContentControl Style="{StaticResource YourStyleTemplateForThisThing}" Width="24"/>

同样适用于大多数属性,希望对您有所帮助。干杯。