0
votes

My tab item is bound to a viewmodel via the content of its contentcontrol

<TabItem>
  <ContentControl Content="{Binding MyVm}" />
</TabItem>

View-ViewModel matching set in the resources of my main :

<DataTemplate DataType="{x:Type MyViewmodelType}">
  <MyView />
</DataTemplate>

No problems here, binding works.

On my view, i have a behavior which populate the view's control with data fetched somewhere. This assignment is done after the InitializeComponent of my view. My problem is, at this time when my view's data is set, its datacontext is not yet assigned, and the data doesn't go all the way to the datacontext.

When the datacontext get set, the bindings are resolved and all the data already in my view is erased. Of course, i need all my view's properties to be in the Two-Way mode.

How can i keep the view data when resolving the bindings for the first time ?

1
Do the assignment in Loaded event of your UserControl.tgpdyk
Indeed, i was reluctant to bind my view loaded event on my mvvm but at least it works. Thanks !Sicha

1 Answers

0
votes

As tagaPdyk suggested, waiting after my view is fully initialized and then loading my data is the good thing to do. Not sure about MVVM compliance but it works.