This is a migrated thread and some comments may be shown as answers.

Delay in instantiating objects?

2 Answers 78 Views
Docking
This is a migrated thread and some comments may be shown as answers.
C Bates
Top achievements
Rank 1
C Bates asked on 19 Jan 2010, 05:52 PM
Hello,
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> 
Code to add a custom control:
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....



2 Answers, 1 is accepted

Sort by
0
Miroslav Nedyalkov
Telerik team
answered on 21 Jan 2010, 09:03 AM
Hello C Bates,

 We didn't notice such problems yet. Could you please open a support ticket and send us a sample project that reproduces the problem and instructions how to reproduce it? This would be very helpful.

Best wishes,
Miroslav Nedyalkov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
C Bates
Top achievements
Rank 1
answered on 23 Jan 2010, 01:43 PM
Thanks for the reply.
After more research,it appears object finalization (as signified by the call to OnApplyTemplate()) is unpredictable.  We have decided on a scheme that, in effect, caches updates for the properties of the template parts and applies them in OnApplyTemplate().

Tags
Docking
Asked by
C Bates
Top achievements
Rank 1
Answers by
Miroslav Nedyalkov
Telerik team
C Bates
Top achievements
Rank 1
Share this question
or