如何根据 XAML 中的值显示图像?
我有性别枚举
[DataContract(Name = "Gender")]
public enum GenderEnum
{
[EnumMember] NotSpecified,
[EnumMember] Male,
[EnumMember] Female,
}
在我的 Model 类中,我有一个名为“Gender”的枚举类型的属性。现在我想通过 XAML 端显示基于“性别”值的图像。
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>