Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF Setting Image.Source from DataTrigger

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>
like image 810
Steve Avatar asked Jan 19 '10 17:01

Steve


2 Answers

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

like image 106
Steve Avatar answered Nov 17 '22 00:11

Steve


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>

like image 43
ExplodingRabbit Avatar answered Nov 17 '22 00:11

ExplodingRabbit