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

Loaded event called twice

3 Answers 982 Views
Docking
This is a migrated thread and some comments may be shown as answers.
Dogu
Top achievements
Rank 1
Dogu asked on 15 Dec 2009, 02:36 PM
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 ?

3 Answers, 1 is accepted

Sort by
0
Miroslav Nedyalkov
Telerik team
answered on 16 Dec 2009, 04:04 PM
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.
0
Makarand
Top achievements
Rank 1
answered on 18 Apr 2013, 09:34 AM
I am facing the same problem  here in WPF,on RowLoaded event same row fire two times,can you provide any solution for that.
0
Miroslav Nedyalkov
Telerik team
answered on 23 Apr 2013, 07:16 AM
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.

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