0

I am working with some multi-trriggers as per this posting. The binding and error are below.

I am using a custom markup extension to display the resource image so it could be suspect but I don't think so since I have used it in styles before.

The error message says I am applying the wrong property for the type and I don't see why yet.

Cheers,
Berryl

triggers

<Style x:Key="AvatarPathImageStyle" TargetType="{x:Type Image}">
    <Setter Property="Source" Value="{Binding AvatarPath}"/>
    <Setter Property="Height" Value="96"/>
    <Setter Property="Width" Value="96"/>
    <Setter Property="Stretch" Value="UniformToFill"/>
    <Style.Triggers>

        <MultiDataTrigger>
            <MultiDataTrigger.Conditions>
                <Condition Binding="{Binding AvatarPath}" Value="{x:Null}" />
                <Condition Binding="{Binding Gender}" Value="{x:Static domain:Gender.Female}"/>
            </MultiDataTrigger.Conditions>
            <Setter Property="Source" Value="{resx:Resx ResxName=Smack.Parties.Presentation.Resources.PersonDetailView, Key=Img_Female}"/>
        </MultiDataTrigger>

        <MultiDataTrigger>
            <MultiDataTrigger.Conditions>
                <Condition Binding="{Binding AvatarPath}" Value="{x:Null}" />
                <Condition Binding="{Binding Gender}" Value="{x:Static domain:Gender.Male}"/>
            </MultiDataTrigger.Conditions>
            <Setter Property="Source" Value="{resx:Resx ResxName=Smack.Parties.Presentation.Resources.PersonDetailView, Key=Img_Male}"/>
        </MultiDataTrigger>
        </MultiDataTrigger>

    </Style.Triggers>
</Style>

binding

<Image Grid.Column="1" Grid.Row="4" 
       HorizontalAlignment="Center" Margin="10, 0" Style="{StaticResource AvatarPathImageStyle}"
      />

error

System.Windows.Markup.XamlParseException occurred
...  InnerException: System.ArgumentException
       Message='System.Windows.Controls.Image' is not a valid value for the 'System.Windows.Controls.Image.Source' property on a Setter.
 ...

update

Accessing the image statically also gets an Invalid Type error:

<Setter Property="Source" Value="{x:Static imgResources:PersonDetailView.Img_Female}"/>
Community
  • 1
  • 1
Berryl
  • 12,471
  • 22
  • 98
  • 182
  • What type is your markup extension returning? – Steve Greatrex May 17 '12 at 16:28
  • @Steve Greatrex. BitmapSource – Berryl May 17 '12 at 16:30
  • @Steve Greatrex. I get an Invalid Type when I access the resx image statically too though (see edited post). – Berryl May 17 '12 at 16:31
  • 1
    I'm guessing that images stored in a resx file are System.Windows.Drawing.Image instances, which aren't directly compatible with WPF. You can write a converter, but unless you have a strong reason for sticking with the resource dictionary I would just embed the images and reference them by URL relative to the the XAML file. – Steve Greatrex May 17 '12 at 19:52
  • @SteveGreatrex. Correct on all counts. You might as well turn your 'answer' into a real answer and leave the bread crumb for someone else. Thanks – Berryl May 18 '12 at 03:06

1 Answers1

1

Comment converted to answer:

The reason for the error is that images stored in a resx file are of type System.Windows.Drawing.Image, which are not directly compatible with WPF. You can write a converter, but unless you have a strong reason for using a resource dictionary I would just embed the images and reference them by URL relative to the XAML file

Steve Greatrex
  • 15,789
  • 5
  • 59
  • 73
  • I did want the images to be from resx and I did have conversion code already on hand so using a converter was the way to go for this one. Cheers – Berryl May 18 '12 at 14:25