2

I have some XAML that does binding of a model to the control that I am creating. However, when the control's 'Loaded' event fires, the binding hasn't completed, so I end up with a null Model.

Is there some way to guarantee that all Binding will be completed before the Loaded event fires on a control?

As a work-around, I modified my code to create the control in the code-behind and set the Model when the parent's Loaded event gets fired.

I would really like to be able to just trust that the Binding would occur before the Loaded event on the child control gets fired.

I have set the Mode of the binding to OneWay and the IsAsync to false. Does anybody have any other suggestions or methods that would help in this situation?

I don't necessarily need to use the Loaded event, but I need some way of knowing when the Model has been set by the Binding. I need information from the model so that I can load additional information from our communications server to populate additional objects that are being displayed in the control.

Thanks for your help.

Curtis
  • 5,794
  • 8
  • 50
  • 77
  • Are you doing some muti-value converters by any chance? Binding can be a bear as it seems to work on its own schedule. – paparazzo Jul 17 '14 at 21:16
  • Why do you need the `Loaded` event anyway? – H.B. Jul 17 '14 at 21:17
  • I can't think of a good reason for you to be trying to access your bound model on the `Loaded` event. Instead try doing whatever you're doing on the [`Binding.SourceUpdated`](http://msdn.microsoft.com/en-us/library/system.windows.data.binding.sourceupdated%28v=vs.110%29.aspx) attached event. – Alain Jul 17 '14 at 21:18
  • Are you sure you want to know when the View is Loaded or do you really want to know when the DataContext has been set? If the latter, you can use the [DataContextChanged](http://msdn.microsoft.com/en-us/library/system.windows.frameworkelement.datacontextchanged%28v=vs.110%29.aspx) event. – Dan Bryant Jul 17 '14 at 21:19
  • The Loaded event usually guarantees that normal bindings have been set and occured. Unless you are doing Async bindings or anything. So i think there must be more to your program that we can guess at this point. Can you show us a small example where its not behaving like you intended? Are you really sure that after the Loaded event the model is set? – dowhilefor Jul 17 '14 at 21:20
  • I don't necessarily need to use the Loaded event, but I need some way of knowing when the Model has been set by the Binding. I need information from the model so that I can load additional information from our communications server to populate additional objects that are being displayed in the control. – Curtis Jul 17 '14 at 21:21
  • 1
    you can set your loaded event priority lower by using dispatcherpriority and then hence can achieve the target – Ashok Rathod Jul 18 '14 at 09:14

0 Answers0