Bitfiddler
Bitfiddler

Reputation: 4202

How to know when all child viewmodels are initialized in Catel?

Looking at the latest overrides available in Catel (build 508 of v4), I can't find one where the method GetChildViewModels() ever returns the child viewmodels in my View. I need to be certain that all my child models are loaded when I start updating my dependency properties that my subviews are bound to. Right now I have an issue where my nested controls do not show the data that they are bound to until you start selecting things on the interface that subsequently fire new changes to the dependency properties. I have verified that the properties in the parent view do in fact have the correct data, the problem (I think) is that the nested controls (child views) are not loaded yet and so the nested views show empty grids.

I have a tree in one nested view and a list in another nested view. The parent view contains them both and has the properties the two subviews are bound to. When the parent view loads, the treeview automatically loads the last selected node. This works. When the node is selected, a message is sent notifying all other components that they should do whatever they need to do with the selected node. The parent component responds to this message and updates a list that the other child view is bound to. I have checked and the list is being updated but the subview is not showing the data. Only when I click on another node does the other subview start showing items in its list. The only thing I can think that would cause this is if the other subview is not yet fully bound when the parent component performs its changes.

Am I going about this the wrong way?

Upvotes: 0

Views: 235

Answers (1)

Bitfiddler
Bitfiddler

Reputation: 4202

The problem was this sneaky little change in 4.0: https://catelproject.atlassian.net/wiki/display/CTL/Mapping+properties+from+view+to+view+model

Starting with 4.0, Catel no longer subscribes to dependency properties automatically

I needed to add:

static MyView()
{
    typeof(MyView).AutoDetectViewPropertiesToSubscribe();
}

To my xaml.cs file to get things back to how they used to work.

Upvotes: 1

Related Questions