简体   繁体   中英

Binding issue : ContentControl, Behavior and viewmodel properties

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 ?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM