Delay in instantiating objects?

3 posts, 0 answers
  1. C Bates
    C Bates avatar
    33 posts
    Member since:
    Oct 2009

    Posted 19 Jan 2010 Link to this post

    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: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"
    <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()  
        Thing nod = new Thing(cntr++ ); 
        RadTabItem tii = _leftTabCntrl.Items[0] as RadTabItem; 
        if (null != tii) { 
            Canvas cvs = tii.Content as Canvas; 
            if (null != cvs) { 
        nod.ApplyTemplate(); // This does not execute; can't step in, breakpoint not hit
        Thing nod2 = new Thing(cntr++ ); 
        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. Miroslav Nedyalkov
    Miroslav Nedyalkov avatar
    1718 posts

    Posted 21 Jan 2010 Link to this post

    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.
  3. C Bates
    C Bates avatar
    33 posts
    Member since:
    Oct 2009

    Posted 23 Jan 2010 Link to this post

    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().

Back to Top