为什么我的绑定不起作用? [英] Why my binding do not work ?
本文介绍了为什么我的绑定不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好
我不明白为什么我的绑定不起作用。
我有带有绑定文本的XML文件:
Hello
I don't understand why my binding do not work.
I have an XML file with a Binding Text :
<TextBlock TextWrapping="Wrap" Text="{Binding strSelectionLignes}" Grid.Column="1" Grid.Row="1" Grid.ColumnSpan="2" />
在我的C#代码中,我一直在使用INotifyPropertyChanged:
In my C# code, i have been use INotifyPropertyChanged :
public partial class ParamsAffichage : Window, INotifyPropertyChanged
{
#region Évenement qui permet de déclencher l'événement INotifyPropertyChanged et mettre à jour le binding
public void Set<TValue>(ref TValue field, TValue newValue, [CallerMemberName] string propertyName = "")
{
if (EqualityComparer<TValue>.Default.Equals(field, default(TValue)) || !field.Equals(newValue))
{
field = newValue;
if (PropertyChanged != null)
PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
public event PropertyChangedEventHandler PropertyChanged;
#endregion
private string _strSelectionLignes;
public string strSelectionLignes
{
get { return _strSelectionLignes; }
set { Set(ref _strSelectionLignes, value); }
}
我修改我的变量strSelectionLignes:
I modify my varaible strSelectionLignes :
public ParamsAffichage()
{
InitializeComponent();
strSelectionLignes = "TEST";
}
但是我的表格中看不到TEST
为什么?
非常感谢
我尝试过:
我试试调试,在这个测试中:
But "TEST" is not visible in my form
Why ?
Thank you very much
What I have tried:
I try in debug, in this test :
if (PropertyChanged != null)
PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
PropertyChanged是alwys null。
PropertyChanged is alwys null.
推荐答案
Of ,对不起,,,,,,
我忘记设置datacontext = this ......
Of, sorry,,,,,,
I forgot to set datacontext = this ......
这篇关于为什么我的绑定不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文