WPF UserControl event called only once?
Posted
by 742
on Stack Overflow
See other posts from Stack Overflow
or by 742
Published on 2010-05-17T09:00:01Z
Indexed on
2010/05/17
9:51 UTC
Read the original article
Hit count: 188
Hi Everyone,
I need to bind two-way a property of a user control to a property of a containing user control. I also need to set a default value to the property from code in the child (cannot be done easily from XAML tags).
If I call my code from the child constructor, the value is set in the parent but the change callback routine is not triggered (my understanding is that the parent doesn't yet exist at the time the child is created).
My current workaround is to catch the Loaded event of the child and to call the code from the handler. Howver as Loaded is called more than once, I need to set a flag to set the property only the first time. I don't like this way, but I don't know if there is a single shot event that could be used, or if this can be done otherwise. Any feedback based on your experience?
© Stack Overflow or respective owner