c# - 将数据绑定(bind)到 Windows Phone 中的可观察集合

标签 c# windows-phone-8 visual-studio-2013 visual-studio-2015

这是我正在使用的类。 Am 通过调用构造函数添加数据。但是图像中的值没有复制IMG变量。所有其他数据均已绑定(bind)。如果我将 IMG 更改为正常的 get; set;,那么绑定(bind)也可以正常工作。设置 IMG 时,该值不会传递给 IMG。我不知道原因。那就是问题所在。请帮忙解决这个问题。

public class ingre : INotifyPropertyChanged
{
    //private string ing;
    private string img { get; set; }
    //private string si;

    public event PropertyChangedEventHandler PropertyChanged;

    public ingre(string image, string name, string shopitem)
    {
        ING = name;
        //string image,
        IMG = image;
        SI = shopitem;

    }


    public string ING
    {
        set;
        get;
    }


    public string IMG 
    {
        get { return img; }
        set
        {
            img = IMG;
            NotifyPropertyChanged("IMG");
        }

    }

    public string SI 
    {
        set;
        get;
    }

    public override string ToString()
    {
        return ING + IMG;
    }

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

最佳答案

试试这个

这是您的 IMG 属性(property)

public string IMG {

    get { return img; }
    set
    {
       if(value != img)
       {
           img = value;
        NotifyPropertyChanged();
       }

    }

这是您的 NotifyPropertyChanged 方法

  private void NotifyPropertyChanged(
                                      [System.Runtime.CompilerServices.CallerMemberName]
                                      string   Property = null) 

{  
   PropertyChanged(this, new PropertyChangedEventArgs(Property));        
}

关于c# - 将数据绑定(bind)到 Windows Phone 中的可观察集合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36028850/

相关文章:

c# - 当我尝试从 Xamarin Samples 运行 Social Framework Demo App 时出现错误

c# - 冒号( :) in url causes error in asp. 网络

c# - C#编译的exe可以集成到网站中吗?

c# - 如何在 Windows Phone 的 ListBox 中获取 "CheckBox.Checked"项目

c# - Windows Phone 8.1 在代码隐藏中手动更改资源文件

c# - 如何防止 resharper 8 使用 nunit 运行并行测试?

c# - 什么是(<类型>?)?

windows-phone-8 - 是否可以使用 Windows Phone 模拟器 8.1 中的计算机摄像头?

c++ - 从 VBA 调用 C++ DLL,出现 "Access violation writing location"错误

c# - 生成的 WSDL 代理具有名为 "System"的类