Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Metro/WinRT/Windows 8 Is it possible to clear the binding of an element from the code behind?

I have a set of items that need to populate a set of TextBox's on a page. Every time the user clicks on a different item I want to remove the old binding from the last item and set the new bindings for the current item. If I don't do this a WinRT The object is immutable exception is thrown.

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

titleBinding.Source = selectedItem;
TitleBox.SetBinding(TextBox.ValueProperty, _titleBinding);
like image 470
Raheel G Avatar asked Oct 18 '12 17:10

Raheel G


2 Answers

You could try calling ClearValue.

TitleBox.ClearValue(TextBox.ValueProperty);
like image 104
AndrewS Avatar answered Nov 07 '22 09:11

AndrewS


The solution for me was to create completely new binding objects each time a new item loaded and then call TitleBox.SetBinding(TextBox.ValueProperty, newBindingObject);

Apparently you can't unbind a Binding object after the source has been set and it has been binded to an object.

like image 25
Raheel G Avatar answered Nov 07 '22 07:11

Raheel G