我已經成功實施了一個數據綁定,但現在它已停止工作......放入一些斷點後,我注意到PropertyChange事件保持爲空。我查找了幾個涉及使用DataContext(不確定放在哪裏)的「解決方案」,但仍然沒有工作...數據綁定成功但財產更改仍然爲空
感謝您的幫助!
它適用於第一初始綁定,但它確實後不入鍋(當屬性發生變化)
我的代碼: 我的綁定:
//databinding
Binding(newProjectile.CurrentVelocity, lbl_angleoftraveloutput, "AngleOfTravel");
private void Binding(velocity Object, Label Output, string Field)
{
Binding newBinding = new Binding();
newBinding.Source = Object;
newBinding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
newBinding.Path = new PropertyPath(Field);
newBinding.Mode = BindingMode.TwoWay;
Output.SetBinding(Label.ContentProperty, newBinding);
}
我的對象(的一部分):
public class velocity : INotifyPropertyChanged, ICloneable
{
public double AngleOfTravel
{
get { return _AngleOfTravel; }
set
{
_AngleOfTravel = value;
OnPropertyChanged("AngleOfTravel");
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string PropertyName)
{
PropertyChangedEventHandler Handler = PropertyChanged;
if (Handler != null)
{
Handler(this, new PropertyChangedEventArgs(PropertyName));
}
}
}
對不起,我複製一個粘貼錯誤的事情:/我只是複製和我對象粘貼的部分 - 現在編輯 – ObnoxiousFrog 2015-02-08 14:54:32
我編輯我的答案 – 2015-02-08 15:02:02
我仍然有同樣的問題:/它綁定在開始但隨着值的變化,它的事件仍爲空 – ObnoxiousFrog 2015-02-08 15:13:57