0

I want to bind a property to a control using Windows Forms Designer.

For example, I have this component:

class MyComponent:Component, INotifyPropertyChanged {
    public event PropertyChangedEventHandler PropertyChanged;
    private string _strProperty;
    [Bindable(true)]
    public string StrProperty {
      get{
        return _strProperty;
      }
      set {
        if (_strProperty != value) {
          _strProperty = value;
          if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs("StrProperty"));
        }
      }
    }
  }

I drag this component from the toolbox and drop it on a form. The component name is myComponent1. On the same form I have a TextBox control named textBox1.
Now I want to bind textBox1.Text property to myComponent1.StrProperty property. I know that I can write in code:

textBox1.DataBindings.Add(new Binding("Text", myComponent1, "StrProperty"));

but I want to achieve the same result using the designer. Is it possible? Should I use a BindingSource?

4

2 に答える 2

2

いいえ、WinForm でコード ビハインドを使用してプロパティをバインドすることしかできません。ただし、C# コードを使用せずに XAML を使用して、WPF でデータをバインドできます。

于 2013-02-08T09:36:53.467 に答える