在 StaticResource Canvas 中为 Path 设置不同的大小或自动调整大小

Sta*_*eff 3 .net c# wpf xaml canvas

ResourceDictionary对所有图标都使用 a ,如下所示:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

    <Canvas x:Key="Icon.Refresh"
            Width="32" Height="32"
            Clip="F1 M 0,0L 32,0L 32,32L 0,32L 0,0">
        <Path Width="28" Height="28"
              Canvas.Left="2" Canvas.Top="2"
              Stretch="Fill"
              Data="..." /> 
    </Canvas>
 </ResourceDictionary>
Run Code Online (Sandbox Code Playgroud)

和实际的 XAML:

<Button Content="{StaticResource Icon.Refresh}"
        Height="40" 
        Width="40" />
Run Code Online (Sandbox Code Playgroud)

这工作正常,因为我的大多数按钮都是这个尺寸。但是当我想在较小的按钮上使用它时,它会溢出按钮:

<Button Content="{StaticResource Icon.Refresh}"
        Height="30" 
        Width="30" />
Run Code Online (Sandbox Code Playgroud)

重新加载按钮

有没有办法设置 a 的大小StaticResource或任何其他聪明的事情可以做?

Kcv*_*vin 5

我想你可以把Canvasa 放在里面<ViewBox>,这样它就会自动缩小。