Metro / WinRT / Windows 8 Can I remove an element's binding from code?

I have a set of elements that need to populate a TextBox set on a page. Every time a user clicks on another element, I want to remove the old anchor from the last element and set new anchors for the current element. If I do not, a WinRT exception is thrown The object is immutable .

This code works when the first item is selected, but throws an exception when the next item is selected.

 titleBinding.Source = selectedItem; TitleBox.SetBinding(TextBox.ValueProperty, _titleBinding); 
+4
source share
2 answers

You can try calling ClearValue.

 TitleBox.ClearValue(TextBox.ValueProperty); 
+5
source

The solution for me was to create completely new binding objects every time I load a new element, and then call TitleBox.SetBinding(TextBox.ValueProperty, newBindingObject);

Apparently, you cannot untie the Binding object after the source has been set and bound to the object.

+1
source

Source: https://habr.com/ru/post/1440616/


All Articles