OKので、ここで(任意の間違いを指摘して自由に感じる)擬似C#コードとして記述され、私の問題のためにいくつかのコンテキストである:(。あなたがスタックトレースに直接ジャンプし、後でコンテキストを読むことができます)親オブジェクトで通知イベントを発生させたときに、Windows Formsのデータバインディングでネストされたブール値のdataboundプロパティを設定するのはなぜですか?
public class SomeForm {
private _model = new ViewModelClass
public void new() {
// Normal Winforms init omitted
ViewModelClassBindingSource.DataSource = _model;
SomeControl1.SetModel(_model);
}
}
public class SomeControl {
private _model = new ViewModelClass
internal void SetModel(ViewModelClass model) {
_model = model;
ViewModelClassBindingSource.DataSource = model;
ViewModelClassBindingSource.ResetBindings(true);
}
}
public class ComplexObject : IPropertyChanging, IPropertyChanged {
public property bool BoolProp {get; set;}
}
public class ViewModelClass : IPropertyChanged {
property IList<ComplexObject> ComplexObjects {get;}
property ComplexObject SelectedComplexObject {get; set;}
property Object SomethingNotNecessarilyRelated {get; set;}
private void NotifyPropertyChanged(string propName) {
PropertyChanged(this, new PropertyChangedEventArgs(propName));
}
}
これらのクラスに記載されているすべてのプロパティは、Visual Studio 2008 Windowsフォームデザイナ、SomeForm
またはSomeControl
クラスでデータバインドされています。 (ComplexObject.BoolProp
は両方ともデータバインドされています)。文脈についてさらに疑問を投げかけてください。
問題:私はいくつかを作るViewModelClass
クラスの通知(の束)が、false
からComplexObject.BoolProp
を設定し、膝ジャーク反応のいくつかの種類がスタックトレースのようなものを使用して、そこにある:
System.dll!System.ComponentModel.ReflectPropertyDescriptor.SetValue(object component = "Object Exposed in 'SelectedComplexObject'", object value = false) + 0x124 bytes
System.Windows.Forms.dll!System.Windows.Forms.BindToObject.SetValue(object value) + 0x5d bytes
System.Windows.Forms.dll!System.Windows.Forms.Binding.PullData(bool reformat, bool force) + 0x15a bytes
System.Windows.Forms.dll!System.Windows.Forms.BindingManagerBase.PullData(out bool success = true) + 0x6e bytes
System.Windows.Forms.dll!System.Windows.Forms.BindingSource.ParentCurrencyManager_CurrentItemChanged(object sender = {System.Windows.Forms.CurrencyManager}, System.EventArgs e) + 0x54 bytes
[Native to Managed Transition]
[Managed to Native Transition]
System.Windows.Forms.dll!System.Windows.Forms.CurrencyManager.OnCurrentItemChanged(System.EventArgs e) + 0x17 bytes
System.Windows.Forms.dll!System.Windows.Forms.CurrencyManager.List_ListChanged(object sender, System.ComponentModel.ListChangedEventArgs e) + 0x3bc bytes
System.Windows.Forms.dll!System.Windows.Forms.BindingSource.OnListChanged(System.ComponentModel.ListChangedEventArgs e) + 0x7e bytes
System.Windows.Forms.dll!System.Windows.Forms.BindingSource.InnerList_ListChanged(object sender, System.ComponentModel.ListChangedEventArgs e) + 0x2e bytes
System.dll!System.ComponentModel.BindingList<System.__Canon>.OnListChanged(System.ComponentModel.ListChangedEventArgs e) + 0x17 bytes
System.dll!System.ComponentModel.BindingList<MyCompany.ViewModelClass>.Child_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) + 0x176 bytes
[Native to Managed Transition]
[Managed to Native Transition]
MyCompany.Gui.exe!MyCompany.ViewModelClass.NotifyPropertyChanged(String propertyName = "SomethingNotNecessarilyRelated") Line 437 + 0x3c bytes Basic
なぜプログラムはSomeBool
をfalse
に設定しますか?そして私はそれをどうやって防ぐことができますか?
ViewModelClassクラスの通知はどのように行われますか?たとえば、コードから、またはユーザーインターフェイスのアクションの結果として、 –
あなたは "SomeBoolをfalseに設定する"と書いています。 BoolPropをfalseに設定する必要がありますか? –