1
votes

Is there any way how to set Image size by WPF styles?

I have in my XAML: <Image Style="MyImageStyle" Source="{StaticResource MyImage}" />

And in ResourceDictionary as a style:

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

But it doesn´t work. I get this error: Cannot resolve the Style Property 'Width'. Verify that the owning type is the Style's TargetType, or use Class.Property syntax to specify the Property.

Thx.

2
Might want to read more about styling... - H.B.

2 Answers

2
votes
Style="{StaticResource MyImageStyle}"

(StaticResource documentation | class documentation)

2
votes
<Style x:Key="myImageStyle" TargetType="{x:Type Image}">
    <Setter Property="Width" Value="30" />
...

<Image Style="{StaticResource MyImageStyle}" Source="{StaticResource MyImage}" />