Loaded event called twice

4 posts, 0 answers
  1. Dogu Tumerdem
    Dogu Tumerdem avatar
    39 posts
    Member since:
    Sep 2006

    Posted 15 Dec 2009 Link to this post

    I have an docking control and adding panes dynamically. But "Loaded" events of the controls called twice. Am I doing something wrong ?
    Here's the XAML:

    <Telerik:RadDocking Grid.Row="1" Name="xamDockManager1">  
                <Telerik:RadSplitContainer InitialPosition="DockedBottom">  
                    <Telerik:RadPaneGroup> 
                        <Telerik:RadDocumentPane Header="Mesajlar" CanUserPin="True" CanFloat="False" CanUserClose="False" IsPinned="False" > 
                            <TextBox Style="{StaticResource StyleTextBoxMessages}" AutoWordSelection="True" Name="TextBoxMessages" HorizontalAlignment="Stretch"  VerticalAlignment="Stretch"  HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" Margin="0" IsReadOnly="True">  
                                <TextBox.ContextMenu> 
                                    <ContextMenu Name="MenuItemMessages">  
                                        <MenuItem Name="MenuItemMessagesClear" Click="MenuItemMessagesClear_Click" Header="Temizle"></MenuItem> 
                                        <MenuItem Name="MenuItemMessagesSave" Click="MenuItemMessagesSave_Click"  Header="Kaydet"></MenuItem> 
                                    </ContextMenu> 
                                </TextBox.ContextMenu> 
                            </TextBox> 
                        </Telerik:RadDocumentPane> 
                    </Telerik:RadPaneGroup> 
                </Telerik:RadSplitContainer> 
                  
                <Telerik:RadDocking.DocumentHost> 
                    <Telerik:RadSplitContainer> 
                        <Telerik:RadPaneGroup Name="documentPaneGroup" SelectionChanged="documentPaneGroup_SelectionChanged">  
                        </Telerik:RadPaneGroup> 
                    </Telerik:RadSplitContainer> 
                </Telerik:RadDocking.DocumentHost> 
            </Telerik:RadDocking> 

    Here's the code to add a pane:
    public RadPane AddPane(UserControl control, bool canBeClosed = true)  
            {  
                RadPane contentPane = new RadPane();  
                contentPane.Content = control;  
                //contentPane.Header = control.Title;  
                contentPane.IsSelected = true;  
                contentPane.CanFloat = false;  
                contentPane.CanUserPin = false;  
     
                documentPaneGroup.AddItem(contentPane, Telerik.Windows.Controls.Docking.DockPosition.Center);  
     
                return contentPane;  
            } 

    Does this mean a control embedded in a RadPane loaded twice ?
  2. Miroslav Nedyalkov
    Admin
    Miroslav Nedyalkov avatar
    1718 posts

    Posted 16 Dec 2009 Link to this post

    Hello Dogu,

     The Loaded event of a visual object is called as many times as it enters the VisualTree. As the Docking control is moving the panes around it attaches and detaches them from the Visual tree so the Loaded event is called multiple times and this is expected. If you need the loaded event to do some initializations you could use a flag and to do your initializations only if the flag is not raised and to rise the flag the first time you hit the Loaded event.

    Hope this helps.


    All the best,
    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. UI for WPF is Visual Studio 2017 Ready
  4. Makarand
    Makarand avatar
    11 posts
    Member since:
    Oct 2011

    Posted 18 Apr 2013 Link to this post

    I am facing the same problem  here in WPF,on RowLoaded event same row fire two times,can you provide any solution for that.
  5. Miroslav Nedyalkov
    Admin
    Miroslav Nedyalkov avatar
    1718 posts

    Posted 23 Apr 2013 Link to this post

    Hello Makarand,

    As I explained in my last post this behavior is normal for the WPF framework - when a visual element is moved from one visual tree to another, its loaded event is fired. If you share with us what issues this behavior causes to your application we could try to help you to resolve them.

    All the best,
    Miroslav Nedyalkov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top