除了 Button 之外,在哪些控件中可以在不定义 Stroke 或 Fill 的情况下显示 WPF Geometry 图标?

In which controls, other than Button, can WPF Geometry icons be shown without defining Stroke or Fill?

我需要显示这样的图标:

<Geometry x:Key="Geometry.LeftArrow">M 6.5 0.5 L 7.5 1 L 7.5 0 L 6.5 0.5 z</Geometry>

如果我将它们放入 Button 中,它们就可以了。但是我需要在许多其他地方展示它们,但没有展示。有时它有助于定义 Stroke/Fill 但这是错误的。我不想编一些硬编码的颜色,当 Theme/Style 改变时看起来很愚蠢。

这个有效:

<Button>
    <Path Data="{StaticResource Geometry.LeftArrow}" Stretch="Uniform" MaxHeight="12"/>
</Button>

这不是:

<Label>
    <Path Data="{StaticResource Geometry.LeftArrow}" Stretch="Uniform" MaxHeight="12"/>
</Label>

那么这里的逻辑是什么?我怎样才能让它们显示在某个 TextBox 旁边呢?

我试过了,路径没有在按钮中获得默认的填充或描边。

我的解决方案是定义默认 Path 样式,将填充(或描边,以哪个为准)设置为 {DynamicResource {x:Static SystemColors.ControlTextBrushKey}}

<Style TargetType="Path">
    <Setter 
        Property="Fill" 
        Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" 
        />
</Style>

一个设计良好的主题应该使用那些 SystemColors 刷键。如果主题设计得不好,您可以添加一些 "shim" 资源定义,这些定义 SystemColors 画笔键到适当的主题资源。

如果我想在 Button 中给 Path 一个默认填充,而不是在其他地方,我可以通过在 [=17] 的资源中定义默认 Path 样式来实现=]风格:

<Style TargetType="Button" BasedOn="{StaticResource {x:Type Button}}">
    <Style.Resources>
        <Style TargetType="Path">
            <Setter 
                Property="Fill" 
                Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" 
                />
        </Style>
    </Style.Resources>

    <!-- other stuff -->
</Style>

现在您已经与您的风格和偶像人物进行了交谈(太棒了;我们必须自己做这些事情),看起来这就是这里发生的事情的本质。