C# 图像源绑定不显示任何内容
我的图像结构如下:C# 图像源绑定不显示任何内容,c#,wpf,xaml,C#,Wpf,Xaml,我的图像结构如下: <Image Height="32" Width="32" Source="{Binding MatchController.Match.TeamHomeShield}" IsEnabled="False" /> private string _teamHomeShield; public string TeamHomeShield { get { return _teamHomeShiel
<Image Height="32" Width="32" Source="{Binding MatchController.Match.TeamHomeShield}" IsEnabled="False" />
private string _teamHomeShield;
public string TeamHomeShield
{
get { return _teamHomeShield; }
set
{
_teamHomeShield = value;
OnPropertyChanged();
}
}
private string _teamAwayShield;
public string TeamAwayShield
{
get { return _teamAwayShield; }
set
{
_teamAwayShield = value;
OnPropertyChanged();
}
}
为什么会发生这种情况?请检查您的图像源格式 “/YourAssemblyName;组件/YourPath/YourImage及其扩展名” xaml:
您可以使用ImageSource属性(非字符串)正确绑定图像 例如:
public ImageSource ImagePath { get; set; }
适用于我的
TeamHomeShield=”http://cache.images.core.optasports.com/soccer/teams/150x150/1270.png“
从internet获取的图像不是绑定问题编译器在ImageSource下划线,似乎无法识别原因?@Vandehusend System.Windows.Media.ImageSource”
<Grid>
<Image Source="{Binding ImagePath}" Width="200" Height="100"/>
</Grid>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
this.DataContext = objviewmodel;
objviewmodel.ImagePath = @"/ImageLoading;component/Assets/Desert.jpg"; // your image path
}
viewmodel objviewmodel = new viewmodel();
}
public class viewmodel : INotifyPropertyChanged
{
#region INotifyPropertyChanged
public event PropertyChangedEventHandler PropertyChanged;
public void OnpropertyChanged([CallerMemberName] string PropertyName = "")
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(PropertyName));
}
}
#endregion
private string _ImagePath=string.Empty;
public string ImagePath
{
get { return _ImagePath; }
set { _ImagePath = value; OnpropertyChanged(); }
}
}
public ImageSource ImagePath { get; set; }