Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
909 B
2
Indexable
Never
public class YourViewModel : INotifyPropertyChanged
{
    private string _imageSource;

    public string ImageSource
    {
        get { return _imageSource; }
        set
        {
            _imageSource = value;
            OnPropertyChanged(nameof(ImageSource));
        }
    }

    public event PropertyChangedEventHandler PropertyChanged;

    protected virtual void OnPropertyChanged(string propertyName)
    {
        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
    }
}

<Style TargetType="Image">
    <Style.Triggers>
        <DataTrigger Binding="{Binding IsPropertyTrue}" Value="True">
            <Setter Property="Source" Value="image_true.png" />
        </DataTrigger>
        <DataTrigger Binding="{Binding IsPropertyTrue}" Value="False">
            <Setter Property="Source" Value="image_false.png" />
        </DataTrigger>
    </Style.Triggers>
</Style>