1

有什么方法可以通过 WPF 样式设置图像大小?

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

在 ResourceDictionary 作为一种风格:

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

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

谢谢。

4

2 回答 2

2
Style="{StaticResource MyImageStyle}"

StaticResource文档|类文档

于 2012-04-21T15:53:50.090 回答
2
<Style x:Key="myImageStyle" TargetType="{x:Type Image}">
    <Setter Property="Width" Value="30" />
...

<Image Style="{StaticResource MyImageStyle}" Source="{StaticResource MyImage}" />
于 2012-04-21T15:59:35.190 回答