通过绑定 wpf 更改后面的图像源代码

Changing Image Source code behind by binding wpf

我正在尝试通过单击某些内容来更改图像源。

我的.xaml

<Canvas Name="img_Canvas" Grid.IsSharedSizeScope="True">
        <Image Source="{Binding ImageType_Source}" Name="autoImage" Margin="5"/>

我的.cs

private string _ImageType_Source;
        public string ImageType_Source
        {
            get { return _ImageType_Source; }
            set { 
                _ImageType_Source = value;
                OnPropertyChanged("ImageType_Source");
            }
        }

        public exImage()
        {
            InitializeComponent();
            DataContext = this;

所以当我点击例如椭圆时,我想改变图像。

private void Ellipse_MouseDown(object sender, MouseButtonEventArgs e)
        {
            ImageType_Source = "/ANKE_Test;component/imagesFolder/Bild_Getriebe.jpg";
            string test = autoImage.Source.ToString();

更改源后,PropertyChangedEvent 被触发,PropertyChanged = null 但使用的是新源。不幸的是,图像中的来源仍然是旧的,没有改变。

在使用 INotifyPropertyChanged 时,我通常会像这样创建自己的 NotifyPropertyChanged 方法:

private void NotifyPropertyChanged(String info) {
        if (PropertyChanged != null) {
            PropertyChanged(this, new PropertyChangedEventArgs(info));
        }
    }

您是否使用 OnPropertyChanged 方法执行此操作?