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

标签 c# .net wpf xaml canvas

我正在为我的所有图标使用 ResourceDictionary,如下所示:

<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>

和实际的 XAML:

<Button Content="{StaticResource Icon.Refresh}"
        Height="40" 
        Width="40" />

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

<Button Content="{StaticResource Icon.Refresh}"
        Height="30" 
        Width="30" />

ReloadButton

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

最佳答案

我想你可以把 Canvas<ViewBox> 里面以便它自动缩小。

关于c# - 在 StaticResource Canvas 中为 Path 设置不同的大小或自动调整大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22657239/

相关文章:

c# - .NET Winforms 垂直进度条文本

c# - 如何获取另一台电脑任务管理器正在运行的程序

c# - 如何在 .NET 中引发事件查看器 "Event"?

c# - Windows 窗体中菜单项的上下文相关帮助

c# - WPF FrameworkElementFactory 图像创建无法为 MouseDownEvent 添加处理程序

c# - “在 'System.Windows.Baml2006.TypeConverterMarkupExtension' 上提供值引发异常。”

c# - syncfusion winrt图表

c# - EF 迁移和时间戳列,无法更新/运行

c# - 在 C# 中解析 html 的最佳方法是什么?

wpf - 从 WPF 3.5 移动到 4.0 会导致错误 "Can' t put a page in a Style"