Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 图像源绑定不显示任何内容_C#_Wpf_Xaml - Fatal编程技术网

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; }