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="{Bi开发者_StackOverflow社区nding 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>
I just changed Property="Source" to Property="Image.Source" and it's working. Thanks everyone
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>
精彩评论