C# WPF中设置绑定时,INotifyPropertyChanged接口如何对数组使用 20
比如说:publicclassA:INotifyPropertyChanged{privatestring[]m_S=newstring[3];publicstring[...
比如说:
public class A: INotifyPropertyChanged
{
private string[] m_S = new string[3];
public string[] S
{
get { return m_S;}
set
{
m_S = value;
if (PropertyChanged != null)
this.PropertyChanged.Invoke(this, new PropertyChangedEventArgs("S"));
}
}
public event PropertyChangedEventHandler PropertyChanged;
}
后台代码:
A a = new A();
Label1.SetBinding(Label.ContentProperty, new Binding("S"){ Source = a});
Label2.SetBinding(Label.ContentProperty, new Binding("S"){ Source = a});
Label3.SetBinding(Label.ContentProperty, new Binding("S"){ Source = a});
实际上我需要Label1的内容与S[0]绑定,Label2的内容与S[1]绑定,Label3的内容与S[2]绑定,属性S和m_S数组也是一一对应的,上述代码应该如何修改才能实现呢 展开
public class A: INotifyPropertyChanged
{
private string[] m_S = new string[3];
public string[] S
{
get { return m_S;}
set
{
m_S = value;
if (PropertyChanged != null)
this.PropertyChanged.Invoke(this, new PropertyChangedEventArgs("S"));
}
}
public event PropertyChangedEventHandler PropertyChanged;
}
后台代码:
A a = new A();
Label1.SetBinding(Label.ContentProperty, new Binding("S"){ Source = a});
Label2.SetBinding(Label.ContentProperty, new Binding("S"){ Source = a});
Label3.SetBinding(Label.ContentProperty, new Binding("S"){ Source = a});
实际上我需要Label1的内容与S[0]绑定,Label2的内容与S[1]绑定,Label3的内容与S[2]绑定,属性S和m_S数组也是一一对应的,上述代码应该如何修改才能实现呢 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询