Hello,
Code to add a custom control:
We are trying to use the MVVM pattern with our application. We have a custom control based on a template. We create RadTabItems programmatically and add our custom control to Canvas contained by the RadTabItem.
The first time a RadTabItem is created, and a control added, there seems to be a delay in the custom control's OnApplyTemplate() being called (suggesting that the control isn't getting added to the visual tree). When a ViewModel object is updated, and the corresponding View object tries to update itself, not all the parts are instantiated.
I have a test app, w/o the MVVM and events and handlers, that I think demonstrates this.
The xaml:
<dock:RadDocking x:Name="Docking" Grid.Column="0" Grid.Row="1" > |
<dock:RadDocking.DocumentHost> |
<dock:RadSplitContainer x:Name="splitContainer1"> |
<dock:RadPaneGroup x:Name="leftMapGroup" > |
<dock:RadPane x:Name="_leftPane" CanDockInDocumentHost="False" CanFloat="False" CanUserClose="False" |
CanUserPin="False" > |
<nav:RadTabControl x:Name="_leftTabCntrl" AllowDragReorder="True"> |
</nav:RadTabControl> |
</dock:RadPane> |
</dock:RadPaneGroup> |
</dock:RadSplitContainer> |
</dock:RadDocking.DocumentHost> |
</dock:RadDocking> |
<Canvas Grid.Column="1" x:Name="rightCanvas"> </Canvas> |
private void addNode_Click(object sender, RoutedEventArgs e) |
{ |
// Add a node to both the docking container and the plain canvas |
if (_leftTabCntrl.Items.Count < 1) { |
RadTabItem ti = new RadTabItem() { Content = new Canvas() |
}; |
_leftTabCntrl.Items.Add(ti); |
} |
Thing nod = new Thing(cntr++ ); |
RadTabItem tii = _leftTabCntrl.Items[0] as RadTabItem; |
if (null != tii) { |
Canvas cvs = tii.Content as Canvas; |
if (null != cvs) { |
cvs.Children.Add(nod); |
} |
} |
nod.ApplyTemplate(); // This does not execute; can't step in, breakpoint not hit |
Thing nod2 = new Thing(cntr++ ); |
rightCanvas.Children.Add(nod2); |
nod2.ApplyTemplate(); // This DOES execute, can step in |
} |
To reiterate, it is possible in our application for the ViewModel object to try to update the View object before the View object (the Thing control) is fully instantiated.
Any suggestions would be appreciated....