Currently my application is built using Prism and MEF. I have a Shell with Prism Regions set on each RadGroup within the main docking control as shown here:
I have utilized the "RadPaneGroupRegionAdapter" (see code below) that I got from one of the forum posts and everything works perfect when the modules are initially loaded and the default views are injected into their respective Regions.
Module code to load views into region on startup...
Seems ok, but when the code is run during runtime the view gets displayed and then closes almost immediately. This happens no matter which region I try and load the view. The other thing I notice is that the code within the "RadPaneGroupRegionAdapter" doesn't get fired when adding a View this way, is this normal?
Either way I'm sure there is something odd going on and I've been banging my head off a wall to try and figure out why when loading these new views after the application is running just display quickly then close. I have even tried doing the same thing using the "RequestNavigate" method within the region manager, but still the same thing.
Any help on this?
<
telerik:RadDocking
Grid.Row
=
"2"
Width
=
"Auto"
Height
=
"Auto"
>
<
telerik:RadDocking.DocumentHost
>
<
telerik:RadSplitContainer
>
<
telerik:RadPaneGroup
x:Name
=
"ShellRegionDockCentral"
prism:RegionManager.RegionName
=
"ShellRegionDockCentral"
/>
</
telerik:RadSplitContainer
>
</
telerik:RadDocking.DocumentHost
>
<
telerik:RadSplitContainer
InitialPosition
=
"DockedLeft"
>
<
telerik:RadPaneGroup
x:Name
=
"ShellRegionDockLeft"
prism:RegionManager.RegionName
=
"ShellRegionDockLeft"
/>
</
telerik:RadSplitContainer
>
<
telerik:RadSplitContainer
InitialPosition
=
"DockedRight"
>
<
telerik:RadPaneGroup
x:Name
=
"ShellRegionDockRight"
prism:RegionManager.RegionName
=
"ShellRegionDockRight"
/>
</
telerik:RadSplitContainer
>
<
telerik:RadSplitContainer
InitialPosition
=
"DockedTop"
>
<
telerik:RadPaneGroup
x:Name
=
"ShellRegionDockTop"
prism:RegionManager.RegionName
=
"ShellRegionDockTop"
/>
</
telerik:RadSplitContainer
>
<
telerik:RadSplitContainer
InitialPosition
=
"DockedBottom"
>
<
telerik:RadPaneGroup
x:Name
=
"ShellRegionDockBottom"
prism:RegionManager.RegionName
=
"ShellRegionDockBottom"
/>
</
telerik:RadSplitContainer
>
</
telerik:RadDocking
>
I have utilized the "RadPaneGroupRegionAdapter" (see code below) that I got from one of the forum posts and everything works perfect when the modules are initially loaded and the default views are injected into their respective Regions.
[Export(
typeof
(RadPaneGroupRegionAdapter))]
public
class
RadPaneGroupRegionAdapter : RegionAdapterBase<RadPaneGroup>
{
[ImportingConstructor]
public
RadPaneGroupRegionAdapter ( IRegionBehaviorFactory regionBehaviorFactory ) :
base
( regionBehaviorFactory )
{
}
protected
override
void
Adapt ( IRegion region, RadPaneGroup regionTarget )
{
region.Views.CollectionChanged += ( s, e ) =>
{
switch
( e.Action )
{
case
NotifyCollectionChangedAction.Add:
foreach
( RadPane item
in
e.NewItems.OfType<RadPane> () )
{
regionTarget.Items.Add ( item );
}
break
;
case
NotifyCollectionChangedAction.Remove:
foreach
( RadPane item
in
e.OldItems.OfType<RadPane> () )
{
item.RemoveFromParent ();
}
break
;
case
NotifyCollectionChangedAction.Replace:
IEnumerable<RadPane> oldItems = e.OldItems.OfType<RadPane> ();
IEnumerable<RadPane> newItems = e.NewItems.OfType<RadPane> ();
IEnumerator<RadPane> newItemsEnumerator = newItems.GetEnumerator ();
foreach
( RadPane oldItem
in
oldItems )
{
var parent = oldItem.Parent
as
ItemsControl;
if
( parent !=
null
&& parent.Items.Contains ( oldItem ) )
{
parent.Items [parent.Items.IndexOf ( oldItem )] = newItemsEnumerator.Current;
if
( !newItemsEnumerator.MoveNext () )
{
break
;
}
}
else
{
oldItem.RemoveFromParent ();
regionTarget.Items.Add ( newItemsEnumerator.Current );
}
}
break
;
case
NotifyCollectionChangedAction.Reset:
regionTarget
.EnumeratePanes ()
.ToList ()
.ForEach ( p => p.RemoveFromParent () );
foreach
(
object
view
in
region.Views )
{
regionTarget.Items.Add ( view );
}
break
;
}
};
foreach
( RadPane view
in
region.Views.OfType<RadPane> () )
{
regionTarget.Items.Add ( view );
}
}
protected
override
IRegion CreateRegion ()
{
return
new
AllActiveRegion () ;
}
}
}
Module code to load views into region on startup...
[ModuleExport(
typeof
(IPTMembersModule), InitializationMode = InitializationMode.OnDemand)]
public
class
PTMembersModule: IPTMembersModule
{
private
IRegionManager _regionManager;
public
void
Initialize()
{
this
._regionManager = ServiceLocator.Current.GetInstance<IRegionManager>();
this
._regionManager.RegisterViewWithRegion(
"ShellRegionDockCentral"
,
typeof
(MembersListingView));
this
._regionManager.RegisterViewWithRegion(
"ShellRegionDockRight"
,
typeof
(MemberDetailsView));
}
}
As mentioned, everything works just perfect and each view is loaded correctly and displayed as it should. The problem that occurs though is when I attempt to inject another View into one of the Regions (either already existing or one that doesn't have anything displayed in it). I have a button on the Shell that when gets clicked, gets handled by a DelegateCommand on the ViewModel side and the code within that is as follows:
IRegion region =
this
.RegionManager.Regions[
"ShellRegionDockLeft"
];
var view =
this
.ServiceLocator.GetInstance(
typeof
(MemberDetailsView2));
if
(region.Views.Contains(view))
{
region.Remove(view);
}
region.Add(view,
"MemberDetailsView2"
);
region.Activate(view);
Seems ok, but when the code is run during runtime the view gets displayed and then closes almost immediately. This happens no matter which region I try and load the view. The other thing I notice is that the code within the "RadPaneGroupRegionAdapter" doesn't get fired when adding a View this way, is this normal?
Either way I'm sure there is something odd going on and I've been banging my head off a wall to try and figure out why when loading these new views after the application is running just display quickly then close. I have even tried doing the same thing using the "RequestNavigate" method within the region manager, but still the same thing.
Any help on this?