Hi everyone,
I'm using PRISM with MEF for modularity with RadDocking Telerik component to display my views into dock.
On my application, I have a Shell with a dockmenu on the left, and a documenthost on the center, here is the Shell.xaml :
I'm using a command in my ShellViewModel to add view in the DocumentHost region, it works correctly :
I overrided the close panel button to remove the view from the Region, it works too (Shell.xaml.cs) :
But, when I drag this pane out of that group (to make it float), and I try to launch the command to load the view again, it prompt me an error in the RadPaneGroupRegionAdapter.cs, on the line "regionTarget.Items.Add(view);" :
Element already has a logical parent. It must be detached from the old parent before it is attached to a new one.
Maybe I forgot something ?
In advance, thanks for your help.
Regards,
Guillaume
I'm using PRISM with MEF for modularity with RadDocking Telerik component to display my views into dock.
On my application, I have a Shell with a dockmenu on the left, and a documenthost on the center, here is the Shell.xaml :
<
telerik:RadDocking
PreviewClose
=
"RadDocking_PreviewClose"
x:Name
=
"dock"
>
<
telerik:RadDocking.DocumentHost
>
<
telerik:RadSplitContainer
>
<
telerik:RadPaneGroup
prism:RegionManager.RegionName
=
"{x:Static const:RegionConstants.CentralRegionName}"
x:Name
=
"centralGroup"
/>
</
telerik:RadSplitContainer
>
</
telerik:RadDocking.DocumentHost
>
<
telerik:RadSplitContainer
x:Name
=
"leftContainer"
InitialPosition
=
"DockedLeft"
>
<!-- Menu -->
<
telerik:RadPaneGroup
x:Name
=
"MenuGroup"
>
<
telerik:RadPane
x:Name
=
"MenuPanel"
Header
=
"Menu"
CanUserClose
=
"False"
>
<
Grid
>
<
Grid.RowDefinitions
>
<
RowDefinition
Height
=
"*"
/>
</
Grid.RowDefinitions
>
<
telerik:RadTreeView
x:Name
=
"principalMenuTreeView"
Grid.Row
=
"1"
VerticalAlignment
=
"Stretch"
IsLineEnabled
=
"True"
ScrollViewer.HorizontalScrollBarVisibility
=
"Auto"
SelectionMode
=
"Single"
IsEditable
=
"False"
IsDragDropEnabled
=
"True"
>
<
telerik:RadTreeViewItem
Header
=
"Monitoring"
IsExpanded
=
"True"
>
<
telerik:RadTreeViewItem
Header
=
"All Customers"
Command
=
"{Binding LoadViewCommand}"
CommandParameter
=
"{x:Static const:ViewConstants.AllCustomersView}"
/>
</
telerik:RadTreeViewItem
>
</
telerik:RadTreeView
>
</
Grid
>
</
telerik:RadPane
>
</
telerik:RadPaneGroup
>
</
telerik:RadSplitContainer
>
</
telerik:RadDocking
>
I'm using a command in my ShellViewModel to add view in the DocumentHost region, it works correctly :
private
void
DisplayViewCommand(
object
viewName)
{
IRegion region =
this
.regionManager.Regions[RegionConstants.CentralRegionName];
object
view =
null
;
switch
(viewName
as
string
)
{
case
ViewConstants.AllCustomersView:
view = ServiceLocator.Current.GetInstance<AllCustomersView>();
break
;
default
:
break
;
}
if
(region.Views.Contains(view))
{
region.Remove(view);
}
region.Add(view);
region.Activate(view);
}
I overrided the close panel button to remove the view from the Region, it works too (Shell.xaml.cs) :
private
void
RadDocking_PreviewClose(
object
sender, StateChangeEventArgs e)
{
if
(e.Panes !=
null
&& e.Panes.Count() > 0)
{
RadPane toDelete = e.Panes.FirstOrDefault();
IRegion mainRegion =
this
.regionManager.Regions[RegionConstants.CentralRegionName];
if
(mainRegion.Views.Contains(toDelete))
{
mainRegion.Remove(toDelete);
}
}
e.Handled =
true
;
}
But, when I drag this pane out of that group (to make it float), and I try to launch the command to load the view again, it prompt me an error in the RadPaneGroupRegionAdapter.cs, on the line "regionTarget.Items.Add(view);" :
Element already has a logical parent. It must be detached from the old parent before it is attached to a new one.
case
NotifyCollectionChangedAction.Reset:
regionTarget
.EnumeratePanes()
.ToList()
.ForEach(p => p.RemoveFromParent());
foreach
(
object
view
in
region.Views)
{
regionTarget.Items.Add(view); /!\ On this line, the exception occurs
}
break
;
Maybe I forgot something ?
In advance, thanks for your help.
Regards,
Guillaume