views:

561

answers:

3

Guys,

I'm trying to define a DataTrigger for an Image element so that it shows a connected/disconnected image. I keep getting an Invalid PropertyDescriptor message. Any ideas?

<Image>
    <Image.Style>
      <Style>
        <Style.Triggers>
          <DataTrigger Binding="{Binding Source={x:Static my:Server.Instance}, Path=Connected, Mode=OneWay}"
                       Value="True">
            <Setter Property="Source"
                    Value="serverconnected.png"/>
          </DataTrigger>

        </Style.Triggers>
      </Style>
    </Image.Style>
  </Image>
+1  A: 

Add a BitmapImage to your resources like so:

<BitmapImage x:Key="serverConnected" UriSource="serverconnected.png" />

And change your existing code to refer to it:

<Image>
<Image.Style>
  <Style>
    <Style.Triggers>
      <DataTrigger Binding="{Binding Source={x:Static my:Server.Instance}, Path=Connected, Mode=OneWay}"
                   Value="True">
        <Setter Property="Source"
                Value="{StaticResource serverConnected}"/>
      </DataTrigger>

    </Style.Triggers>
  </Style>
</Image.Style>

ExplodingRabbit
This was a nice suggestion but was not the solution to the problem. +1 for the quick reply!
Steve
A: 

I just changed Property="Source" to Property="Image.Source" and it's working. Thanks everyone

Steve
A: 

Steve, thanks for posting your solution, just what I was looking for!

Janene

Janene
Stack Overflow isn't a discussion site, there's no need to post things like this. If you found the question and/or answer useful then vote them up (the triangle above the big number on the left). That's the best sort of thanks you can give someone.
ChrisF
Chris, I'm not able to vote up, hence my post. I was banging my head for quite awhile and appreciated Steve taking the time. Many don't.
Janene