Hello
Please refer to the telerik "Save/Load the Content of the Panes" docking topic. I'm trying to load the layout of my docking control in this way when navigating away and then returning to this screen to maintain view state. This page refers to the following piece of code:
I assume that "GetPaneContent" refers to some internal method in the code-behind which returns the content, whatever that control may have been before the content was saved. Since I am using MVVM and adding RadPanes and RadPaneGroups dynamically in my view model, I maintain a dictionary of the pane contents by the serialization tag that I assign to each one. This view model code is as follows:
To explain, chartConfiguration.Id is a Guid which serves as a string tag and hostedCharts is a field of type Dictionary<Guid, ChartView>.
I use this dictionary to get the ChartView when I reload the layout. ChartView is the content I want to reset as the content of the pane.
My element loading event handler looks like this:
// This entire section is to try to remove the chart from its parent all the way up the visual tree.
// This section is here because the pane groups fill up the entire space if I leave it out (They seem to be aligned to Stretch)
Here's my concern:
Firstly, if I remove the code to try to remove the ChartView from its parent, I get an InvalidOperationException saying to first disconnect the element before adding it to a new one on the line, "newPane.Content = chartView;" . It seems that the entire visual tree is still intact and reloading the screen creates new visual elements and adds these to the Docking component. Is this not memory intensive? Please note that this screen's (my screen, "ChartHostView")'s lifestyle is Transient and may be affecting the way it should work.
Secondly, my pane groups are not being loaded in the state that I saved them in. Why is it necessary for me re-set their Vertical Alignment ?
Please let me know if I am going about this the completely wrong way.
Thank you.
Please refer to the telerik "Save/Load the Content of the Panes" docking topic. I'm trying to load the layout of my docking control in this way when navigating away and then returning to this screen to maintain view state. This page refers to the following piece of code:
private
void
radDocking_ElementLoading(
object
sender, Telerik.Windows.Controls.LayoutSerializationLoadingEventArgs e )
{
var pane = e.AffectedElement
as
RadPane;
if
( pane !=
null
)
{
pane.Content =
this
.GetPaneContent( e.AffectedElementSerializationTag );
}
}
I assume that "GetPaneContent" refers to some internal method in the code-behind which returns the content, whatever that control may have been before the content was saved. Since I am using MVVM and adding RadPanes and RadPaneGroups dynamically in my view model, I maintain a dictionary of the pane contents by the serialization tag that I assign to each one. This view model code is as follows:
RadPaneGroup radPaneGroup =
new
RadPaneGroup { VerticalAlignment = VerticalAlignment.Top, VerticalContentAlignment = VerticalAlignment.Top };
this
.view.splitContainer.Items.Add(radPaneGroup);
RadPane radPane =
new
RadPane
{
Content = createdChartView,
CanUserClose =
true
,
Title = createdChartView.DisplayName,
};
RadDocking.SetSerializationTag(radPane, chartConfiguration.Id.ToString());
RadDocking.SetSerializationTag(radPaneGroup, chartConfiguration.Id.ToString());
radPaneGroup.Items.Add(radPane);
this
.hostedCharts.Add(chartConfiguration.Id, createdChartView);
To explain, chartConfiguration.Id is a Guid which serves as a string tag and hostedCharts is a field of type Dictionary<Guid, ChartView>.
I use this dictionary to get the ChartView when I reload the layout. ChartView is the content I want to reset as the content of the pane.
My element loading event handler looks like this:
private
void
RadDockingOnElementLoaded(
object
sender, LayoutSerializationEventArgs e)
{
RadPane newPane = e.AffectedElement
as
RadPane;
if
(newPane !=
null
)
{
ChartView chartView = ((ChartHostViewModel)
this
.DataContext).GetPaneContent(e.AffectedElementSerializationTag);
// This entire section is to try to remove the chart from its parent all the way up the visual tree.
RadPane oldParentPane = (RadPane)chartView.Parent;
if
(oldParentPane !=
null
)
{
RadPaneGroup oldParentGroup = (RadPaneGroup)oldParentPane.Parent;
if
(oldParentGroup !=
null
)
{
RadSplitContainer oldSplitContainer = (RadSplitContainer)oldParentGroup.Parent;
if
(oldSplitContainer !=
null
)
{
oldSplitContainer.Items.Remove(oldParentGroup);
}
oldParentGroup.Items.Remove(oldParentPane);
}
oldParentPane.Content =
null
;
}
newPane.Content = chartView;
return
;
}
// This section is here because the pane groups fill up the entire space if I leave it out (They seem to be aligned to Stretch)
RadPaneGroup newPaneGroup = e.AffectedElement
as
RadPaneGroup;
if
(newPaneGroup !=
null
)
{
newPaneGroup.VerticalAlignment = VerticalAlignment.Top;
newPaneGroup.VerticalContentAlignment = VerticalAlignment.Top;
}
}
Here's my concern:
Firstly, if I remove the code to try to remove the ChartView from its parent, I get an InvalidOperationException saying to first disconnect the element before adding it to a new one on the line, "newPane.Content = chartView;" . It seems that the entire visual tree is still intact and reloading the screen creates new visual elements and adds these to the Docking component. Is this not memory intensive? Please note that this screen's (my screen, "ChartHostView")'s lifestyle is Transient and may be affecting the way it should work.
Secondly, my pane groups are not being loaded in the state that I saved them in. Why is it necessary for me re-set their Vertical Alignment ?
Please let me know if I am going about this the completely wrong way.
Thank you.