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

BUG: Adding a RadPane using code behind leads to an exception when loading the adding control for a second time

6 Answers 111 Views
Docking
This is a migrated thread and some comments may be shown as answers.
Jens
Top achievements
Rank 1
Jens asked on 22 Jul 2009, 12:47 PM
What we did:
We use a mechanism to switch the content on a Silverlight page inside a ContentPresenter.
The control loaded into the content of the ContentPresenter dynamically adds RadPanes using code behind.
This control is triggered when the "OnLoad" event occurs.
The control then adds a RadPane to a RadPaneGroup.

What happens:
When loading the control for the first time everything goes well.
When loading the control the second time (by reloading the content of the ContentPresenter) an exception occurs, while trying to add the new RadPane using "AddItem" on the RadPaneGroup.

Steps to reproduce:
I published the test solution at: http://jens-schaller.de/downloads/TelerikRadDocking.zip
When running it, there are two buttons: "Page1" and "Page2".
When pressing any button for the first time everything works.
Pressing the same or the other button a second time leads to an exception.

I really hope you can provide help, since this is a real showstopper bug for us.

Thanks.
Jens Schaller

6 Answers, 1 is accepted

Sort by
0
Kaloyan
Telerik team
answered on 22 Jul 2009, 07:10 PM
Hi Jens,

We are sorry for the inconvenienced caused. You can fix the problem by using the code posted below and in the meantime we are going to analyze the specifics of the current issue.
if (m_defaultPane == null) OnApplyTemplate(); 
 
            RadPane pane = new RadPane(); 
            pane.Title = "Pane2"
            pane.Header = "Pane2"
            pane.CanUserClose = false
            pane.CanDockInDocumentHost = false
            pane.Content = new Button() { Content = "button2" }; 
            pane.Tag = "tag"
           
            m_defaultPane.Items.Add(pane); 
            RadDocking.SetSerializationTag(pane, "abc"); 


Sincerely yours,
Kaloyan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Jens
Top achievements
Rank 1
answered on 23 Jul 2009, 07:24 AM
Hey Kaloyan,

I am sorry, but the workaround you proposed changes the behavior when adding the panes:
When using the AddItem method, you can provide a docking, which in our case arranges the panes side by side.
With your method the panes will be arranged in tabs, which won't work for us.

I really hope you can solve this soon.

Thanks.
Jens

0
Kaloyan
Telerik team
answered on 24 Jul 2009, 08:32 AM
Hello Jens,

Once again we are sorry. We have checked your code and finally found the reason that is causing the issue. The problem is the name of the Button - (pane.Content = new Button() { Name = "button2" }). Once added it is not possible to add it again with the same name. Consider removing the name or as a better solution you can change the inherited class of the PageControl to be UserControl instead control as the UserControl exists in a different NameScope.

Kind regards,
Kaloyan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Jens
Top achievements
Rank 1
answered on 24 Jul 2009, 09:33 AM
THAT is the core problem, but the cause for this lies in the docking control:
If you just set the content of the ContentPresenter to a button called "button2" and then reload the page, it works like a charm.
If you wrap the button inside a RadPane it won't.
So it seems, that the RadPane or some other docking objekt is holding some references to the old instance of "button2" forcing it to stay inside the UI tree.

Once again: If you replace the content of a ContentPresenter, it's no problem at all to add a control under the same name!

Thanks.
Jens
0
Accepted
Kaloyan
Telerik team
answered on 24 Jul 2009, 12:33 PM
Hello Jens,

In that case when you add the button directly in to the ContentPresenter the page create a weak referacne to this button. When you add it for a second time the first reference is destroyed. Meanwhile in your code, page creates a strongly type reference to this PageControl. Which is the problem here. You can try to remove the RadDocking control and just add the button in the main grid for example. The same arror appears
    <UserControl.Resources> 
        <Style x:Key="pageStyle" TargetType="this:PageControl"
            <Setter Property="Template"
                <Setter.Value> 
public PageControl() 
        { 
            DefaultStyleKey = typeof(PageControl); 
        } 
 
        public override void OnApplyTemplate() 
        { 
            base.OnApplyTemplate(); 
            m_defaultPane = (Grid)GetTemplateChild("docking"); 
        } 
 
        Grid m_defaultPane; 
 
        public void AddPane() 
        { 
            if (m_defaultPane == null) OnApplyTemplate(); 
 
            m_defaultPane.Children.Add(new Button() { Name = "button2" }); 
 
            //RadPane pane = new RadPane(); 
            //pane.Title = "Pane2"; 
            //pane.CanUserClose = false; 
            //pane.CanDockInDocumentHost = false; 
            //pane.Content = new Button() { Name = "button2" }; 
            //pane.Tag = "tag"; 
 
            //m_defaultPane.AddItem(pane, DockPosition.Left); 
            //RadDocking.SetSerializationTag(pane, "abc"); 
        } 
                    <ControlTemplate TargetType="this:PageControl"
                        <Grid x:Name="docking"
                             
                        </Grid> 
                    </ControlTemplate> 
                </Setter.Value> 
            </Setter> 
        </Style> 
    </UserControl.Resources> 
    <Grid x:Name="LayoutRoot" Background="White"
        <Grid.RowDefinitions> 
            <RowDefinition/> 
            <RowDefinition/> 
        </Grid.RowDefinitions> 
        <StackPanel Orientation="Horizontal"
            <Button x:Name="Page1" Content="Page1" Click="Page1_Click"/> 
            <Button x:Name="Page2" Content="Page2" Click="Page2_Click"/> 
        </StackPanel> 
        <ContentPresenter x:Name="Workspace" Grid.Row="1"/> 
    </Grid> 


Best wishes,
Kaloyan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Jens
Top achievements
Rank 1
answered on 03 Aug 2009, 01:04 PM
Oops, you are right. Thank you very much for pushing us in the right direction!
Tags
Docking
Asked by
Jens
Top achievements
Rank 1
Answers by
Kaloyan
Telerik team
Jens
Top achievements
Rank 1
Share this question
or