Does data binding support nested properties in Windows Forms?

后端 未结 1 621
情书的邮戳
情书的邮戳 2020-12-06 11:41

I am writing the test application in Windows Forms. It has a simple form with TextBox and needs to implement DataBinding. I have implemented the class FormViewModel to hold

相关标签:
1条回答
  • 2020-12-06 12:09

    The Databinding behavior was changed in .NET 4.0. Your code works on .NET 3.5. I found this issue posted at Microsoft Connect: .Net 4.0 simple binding issue

    Here was the work-around that worked for me. Use a BindingSource as the data object:

    BindingSource bs = new BindingSource(_viewModel, null);
    
    //textBox1.DataBindings.Add("Text", _viewModel, "CurrentObject.TestPropertyString");
    textBox1.DataBindings.Add("Text", bs, "CurrentObject.TestPropertyString");
    
    0 讨论(0)
提交回复
热议问题