【发布时间】:2020-11-01 06:56:25
【问题描述】:
我在 wpf 应用程序中有一个图像并将其 Source 属性绑定到视图模型中的 System.Windows.Controls.Image 但它不起作用。但是当我将其 Source 属性绑定到 BitmapImage 时,它正在工作。有没有办法将 Source 属性绑定为 System.Windows.Controls.Image ?
Xaml 部分
<Image x:Name="ShipMainImage" Source="{Binding MainImageSource}" />
查看模型部分
public class StabilityVM : INotifyPropertyChanged {
private System.Windows.Controls.Image mainImageSource;
public System.Windows.Controls.Image MainImageSource
{
get { return mainImageSource; }
set {
mainImageSource = value;
OnPropertyChanged(nameof(MainImageSource)); }
}
protected virtual void OnPropertyChanged(string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
public event PropertyChangedEventHandler PropertyChanged;
}
【问题讨论】:
标签: c# wpf image bitmapimage