Alex Rivera | Logout

Remove binding in WPF using code

Asked 2008-10-09T09:05:28.660
64

I would like to use databinding when displaying data in a TextBox. I'm basically doing like:

 public void ShowRandomObject(IRandomObject randomObject) {
        Binding binding = new Binding {Source = randomObject, Path = new PropertyPath("Name")};
        txtName.SetBinding(TextBox.TextProperty, binding);
    }

I can't seem to find a way to unset the binding. I will be calling this method with a lot of different objects but the TextBox will remain the same. Is there a way to remove the previous binding or is this done automatically when I set the new binding?

Edit
Report

1 Answer

19

How about:

this.ClearValue(TextBox.TextProperty);

It's much cleaner I think ;)

answered 2008-10-09T11:44:40.023

Your Answer