Question: Cleaning up and removing all bindings from a control #7451
Unanswered
rick-palmsens
asked this question in
Q&A
Replies: 2 comments
-
I would probably recommend looking into the revoker pattern but instead of using the revokers destructor you can have the revokere subscribe to the controls unloaded event. Either that or call GC.Collect manually to make sure that you don't have the stale bindings set up. One way or another you'll need to "manually" disconnect a binding that you think is no longer valid. |
Beta Was this translation helpful? Give feedback.
0 replies
-
The documentation is a bit unclear about this, but should I use DependencyObject.ClearValue to remove the bindings? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have made a custom property control that automatically changes the input field based on the type of value that is bound to it. So a
CheckBox
forbool
, aNumberBox
fordouble
, etc. All of this is done from code behind.This works fine until I switch between values. That it when I start getting these errors in the output window:
Converter failed to convert value of type 'Windows.Foundation.Boolean' to type 'Double'; BindingExpression: Path='Value' DataItem='PalmSens.Core.Presentation.Controls.ParameterControl'; target element is 'Microsoft.UI.Xaml.Controls.NumberBox' (Name='null'); target property is 'Value' (type 'Double').
I think that because the garbage collection has not yet kicked in, the old detached control is still weakly bound to the value, which no longer has the correct type for that binding.
So how do I nicely dispose of the bindings of an old control? Preferably without keeping track of every specific binding.
Beta Was this translation helpful? Give feedback.
All reactions