How do I stop binding properties from updating?

后端 未结 3 1514
长发绾君心
长发绾君心 2021-02-06 01:30

I have a dialog that pops up over the main screen (it\'s actually a user control that appears on the page as per the application demo from Billy Hollis) in my application that h

3条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-06 02:02

    I also choose to use BindingGroup. But instead of BeginEdit() / CommitEdit() / CancelEdit() pattern I call UpdateSource() explicitly on all the bindings associated with BindingGroup. This approach allows me to add only one event handler instead of 3.

    private void OkButton_Click(object sender, RoutedEventArgs e)
    {
        CommitChanges();
        DialogResult = true;
        Close();
    }
    
    private void CommitChanges()
    {
        foreach (var bindingExpression in this.BindingGroup.BindingExpressions)
        {
            bindingExpression.UpdateSource();
        }
    }
    

提交回复
热议问题