How can I display an image based on a value in XAML?
I have gender enumeration
[DataContract(Name = "Gender")]
public enum GenderEnum
{
[EnumMember] NotSpecified,
[EnumMember] Male,
[EnumMember] Female,
}
At my Model class I have a property of that enumeration type called "Gender". Now I want to display an image based on the value of "Gender" via the XAML side.
XAML:
<Image Tag="{Binding Gender}" Width="48" Height="48">
<Image.Style>
<Style TargetType="Image">
<Style.Triggers>
<DataTrigger Binding="{Binding Gender}" Value="Male">
<Setter Property="Source" Value="/Resources/Client_Male.png"/>
</DataTrigger >
<DataTrigger Binding="{Binding Gender}" Value="Female">
<Setter Property="Source" Value="/Resources/Client_Female.png"/>
</DataTrigger >
</Style.Triggers>
</Style>
</Image.Style>
</Image>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With