【问题标题】:Setting Image width and height by WPF styles通过 WPF 样式设置图像宽度和高度
【发布时间】:2012-05-02 21:09:33
【问题描述】:

有没有办法通过 WPF 样式设置图像大小?

我的 XAML 中有: <Image Style="MyImageStyle" Source="{StaticResource MyImage}" />

并在 ResourceDictionary 中作为样式:

<Style x:Key="MyImageStyle">
<Setter Property="Width" Value="30" />

但它不起作用。我收到此错误:无法解析样式属性“宽度”。验证所属类型是否为 Style 的 TargetType,或使用 Class.Property 语法指定 Property。

谢谢。

【问题讨论】:

  • 可能想了解更多关于styling...

标签: wpf xaml styles


【解决方案1】:
Style="{StaticResource MyImageStyle}"

(StaticResource documentation | class documentation)

【讨论】:

    【解决方案2】:
    <Style x:Key="myImageStyle" TargetType="{x:Type Image}">
        <Setter Property="Width" Value="30" />
    ...
    
    <Image Style="{StaticResource MyImageStyle}" Source="{StaticResource MyImage}" />
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-04-14
      • 1970-01-01
      • 1970-01-01
      • 2012-03-01
      • 2014-06-21
      • 2016-02-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多