[英]Metro/WinRT/Windows 8 Is it possible to clear the binding of an element from the code behind?
我有一組項目需要填充頁面上的一組TextBox
。 每次用戶單擊其他項目時,我都想從最后一個項目中刪除舊的綁定,並為當前項目設置新的綁定。 如果我不這樣做, The object is immutable
引發WinRT The object is immutable
。
該代碼在選擇第一個項目時起作用,但在下一個選擇項上引發異常。
titleBinding.Source = selectedItem;
TitleBox.SetBinding(TextBox.ValueProperty, _titleBinding);
您可以嘗試調用ClearValue。
TitleBox.ClearValue(TextBox.ValueProperty);
對我來說,解決方案是每次加載新項目時創建一個全新的綁定對象,然后調用TitleBox.SetBinding(TextBox.ValueProperty, newBindingObject);
顯然,在設置源並將其綁定到對象之后,您將無法取消Binding
對象。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.