enabled-properties多个控件绑定到相同的数据源属性Bind enabled-properties of multiple controls to the same DataSource property

- 此内容更新于:2015-01-06
主题:

原文:

Beginning with an ModelViewPresenter Architecture I'm trying to bind the Enabled-Properties of 5 Checkboxes to the same boolean property of the DataSource instance.

This property must be a) set at runtime programmatically b) set, when the user clicks another checkbox

When I click at runtime (to uncheck) on the checked CheckBox mentioned in b), NotifyPropertyChanged is correctly called, but only the first of my 5 databound Checkboxes receives an EnabledChanged event and is displayed in gray.

The other 4 Checkboxes do not receive EnabledChanged, are displayed in white, but behave like disabled (do not respond on click).

When checking the CheckBox mentioned in b), all 5 databound CheckBoxes are receiving EnabledChanged-Events as expected.

Same behaviour everytime if I bind more than one Checkbox.Enabled to the enabled-property of the Presenter.

Why does this not work? What can I do other than implementing the DataSources Enabled property 5 times?

private void bindSettings()
{
    if (!m_WereDataBindingsCreated)
    {
        var binding = new BindingSource();
        binding.DataSource = m_Presenter;
        ...        

        CheckBox1.DataBindings.Add("Enabled", binding, "Enabled", false, DataSourceUpdateMode.OnPropertyChanged);

        CheckBox2.DataBindings.Add("Enabled", binding, "Enabled", false, DataSourceUpdateMode.OnPropertyChanged);

        CheckBox3.DataBindings.Add("Enabled", binding, "Enabled", false, DataSourceUpdateMode.OnPropertyChanged);

        CheckBox4.DataBindings.Add("Enabled", binding, "Enabled", false, DataSourceUpdateMode.OnPropertyChanged);

        CheckBox5.DataBindings.Add("Enabled", binding, "Enabled", false, DataSourceUpdateMode.OnPropertyChanged)    
        ...

        m_WereDataBindingsCreated = true;
}