Remove binding in WPF using code

前端 未结 4 1014
小蘑菇
小蘑菇 2020-12-29 18:09

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

 public void ShowRandomObject(IRandomObject randomObject) {
            


        
相关标签:
4条回答
  • 2020-12-29 18:19

    Alternately:

    BindingOperations.ClearBinding(txtName, TextBox.TextProperty)
    
    0 讨论(0)
  • 2020-12-29 18:29

    When available

    BindingOperations.ClearBinding(txtName, TextBox.TextProperty)
    

    For older SilverLight versions, but not reliable as stated in comments:

    txtName.SetBinding(TextBox.TextProperty, null);
    

    C# 6.0 features enabled

    this.btnFinish.ClearBinding(ButtonBase.CommandProperty);
    
    0 讨论(0)
  • 2020-12-29 18:30

    How about:

    this.ClearValue(TextBox.TextProperty);
    

    It's much cleaner I think ;)

    0 讨论(0)
  • 2020-12-29 18:33

    How about just

    txtName.Text = txtName.Text;
    

    You would have to set the value after clearing it anyways. This works in SL4 at least.

    0 讨论(0)
提交回复
热议问题