Quantcast
Channel: DevExpress Support Center (Examples)
Viewing all articles
Browse latest Browse all 7205

Prism - How to define Prism regions for various DXDocking elements

$
0
0

Since Prism RegionManager supports standard controls only, it is necessary to write custom RegionAdapters (a descendant of the Microsoft.Practices.Prism.Regions.RegionAdapterBase class) in order to instruct Prism RegionManager how to deal with DXDocking elements.

This example covers the following scenarios:

Using a LayoutPanel as a Prism region. The LayoutPanelAdapter class creates a new ContentControl containing a View and then places it into a target LayoutPanel.

Using a LayoutGroup as a Prism region. The LayoutGroupAdapter creates a new LayoutPanel containing a View, and then adds it to a target LayoutGroup’s Items collection,

Using a DocumentGroup as a Prism region. The DocumentGroupAdapter behaves similarly to the LayoutGroupAdapter. The only difference is that it manipulates DocumentPanels.

Question Comments

Added By: K.Wessing at: 6/21/2012 1:19:15 AM    

starting in version 12.1 I get an exception, in version 11.2 the sample did work
(I based my application on this)

System.ArgumentException was unhandled by user code
  Message=This RegionManager does not contain a Region with the name 'LeftRegion'.
Parameter name: regionName
  Source=Microsoft.Practices.Prism
  ParamName=regionName
  StackTrace:
       at Microsoft.Practices.Prism.Regions.RegionManagerExtensions.AddToRegion(IRegionManager regionManager, String regionName, Object view)
       at PrismOnDXDocking.ExampleModule.ExampleModule.Initialize() in C:\Users\k.wessing\Documents\Samples\DXDocking for WPF\12.1.4\E3339\PrismOnDXDocking.ExampleModule\Module.cs:line 58
       at Microsoft.Practices.Prism.Modularity.ModuleInitializer.Initialize(ModuleInfo moduleInfo)
  InnerException:

Added By: Allan Nielsen 2 at: 7/3/2012 6:45:45 PM    

I downloaded this example and tried to run it via your example runner. We are using DXv2 (12.1) and it generates an exception as found by K.Wessing above. I also made sure I was using an up-to-date version of Prism Mef (v4.1):

System.ComponentModel.Composition.CompositionException was unhandled
  Message=The composition produced a single composition error. The root cause is provided below. Review the CompositionException.Errors property for more detailed information.

1) This RegionManager does not contain a Region with the name 'LeftRegion'.
Parameter name: regionName

Resulting in: An exception occurred while initializing module 'ExampleModule'.
    - The exception message was: This RegionManager does not contain a Region with the name 'LeftRegion'.
Parameter name: regionName
    - The Assembly that the module was trying to be loaded from was:PrismOnDXDocking.ExampleModule, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
    Check the InnerException property of the exception for more information. If the exception occurred while creating an object in a DI container, you can exception.GetRootException() to help locate the root cause of the problem.
  

Resulting in: An exception occurred while calling the 'OnImportsSatisfied' method on type 'Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleManager'.

Resulting in: Cannot activate part 'Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleManager'.
Element: Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleManager --> Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleManager --> AssemblyCatalog (Assembly="Microsoft.Practices.Prism.MefExtensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35")

Resulting in: Cannot get export 'Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleManager (ContractName="Microsoft.Practices.Prism.Modularity.IModuleManager")' from part 'Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleManager'.
Element: Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleManager (ContractName="Microsoft.Practices.Prism.Modularity.IModuleManager") --> Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleManager --> AssemblyCatalog (Assembly="Microsoft.Practices.Prism.MefExtensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35")

  Source=System.ComponentModel.Composition
  StackTrace:
       at System.ComponentModel.Composition.Hosting.CompositionServices.GetExportedValueFromComposedPart(ImportEngine engine, ComposablePart part, ExportDefinition definition)
       at System.ComponentModel.Composition.Hosting.CatalogExportProvider.GetExportedValue(ComposablePart part, ExportDefinition export, Boolean isSharedPart)
       at System.ComponentModel.Composition.Hosting.CatalogExportProvider.CatalogExport.GetExportedValueCore()
       at System.ComponentModel.Composition.Primitives.Export.get_Value()
       at System.ComponentModel.Composition.ExportServices.GetExportedValueFromLazy[T](Export export)
       at System.ComponentModel.Composition.Hosting.ExportProvider.GetExportedValueCore[T](String contractName, ImportCardinality cardinality)
       at System.ComponentModel.Composition.Hosting.ExportProvider.GetExportedValue[T](String contractName)
       at System.ComponentModel.Composition.Hosting.ExportProvider.GetExportedValue[T]()
       at Microsoft.Practices.Prism.MefExtensions.MefBootstrapper.InitializeModules()
       at Microsoft.Practices.Prism.MefExtensions.MefBootstrapper.Run(Boolean runWithDefaultConfiguration)
       at Microsoft.Practices.Prism.Bootstrapper.Run()
       at PrismOnDXDocking.App.OnStartup(StartupEventArgs e) in C:\Users\anielsen\Downloads\DXDocking for WPF\12.1.4\E3339\PrismOnDXDocking\Application.xaml.cs:line 34
       at System.Windows.Application.<.ctor>b__1(Object unused)
       at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
       at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
       at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
       at System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
       at System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Int32 numArgs)
       at System.Windows.Threading.DispatcherOperation.InvokeImpl()
       at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
       at System.Threading.ExecutionContext.runTryCode(Object userData)
       at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Windows.Threading.DispatcherOperation.Invoke()
       at System.Windows.Threading.Dispatcher.ProcessQueue()
       at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
       at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
       at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
       at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
       at System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
       at System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Int32 numArgs)
       at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
       at System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority, Delegate method, Object arg)
       at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
       at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
       at System.Windows.Threading.Dispatcher.TranslateAndDispatchMessage(MSG& msg)
       at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
       at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
       at System.Windows.Threading.Dispatcher.Run()
       at System.Windows.Application.RunDispatcher(Object ignore)
       at System.Windows.Application.RunInternal(Window window)
       at System.Windows.Application.Run(Window window)
       at System.Windows.Application.Run()
       at PrismOnDXDocking.App.Main() in C:\Users\anielsen\Downloads\DXDocking for WPF\12.1.4\E3339\PrismOnDXDocking\obj\x86\Debug\Application.g.cs:line 50
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException:

Added By: jplopez42 at: 7/4/2012 1:18:46 AM    

Hello, we have an issue with your sample E3339 (related to the use of regions and adapters). The sample is successfully working with the 11.2.11 version in one of our testing computers. But we’re now integrating the last version of DevExpress (12.1.4) in our sandbox computer and it doesn’t work: the project is compiling but it doesn’t work (the adapters aren’t working: the flow execution isn’t entering in the adapters, in the function Adapt). We’re experiencing the same problem than K.Wessing: System.ArgumentException was unhandled by user code
  Message=This RegionManager does not contain a Region with the name 'LeftRegion'.
We have been checking your technical support and it seems there was another issue between the 11.1.x and the 11.2.x, and your teams adapted the sample project for the new DevExpress version. Is it possible that it’s happening the same?
Thanks,
       Juan Lopez

Added By: Bertrand Decoux at: 8/23/2012 8:55:43 PM    

I am using the LayoutGroupAdapter
I would like to be able to switch from one view to an other within the same LayoutGroup region.
I 've added the Remove action:
 if (e.Action == NotifyCollectionChangedAction.Remove)
            {
regionTarget.Items.Clear();
}
Scenario:
in region : <dxd:LayoutGroup cal:RegionManager.RegionName="{x:Static Infrastructure:RegionNames.DetailsRegion}" />
#1 Add a viewA - OK
#2 Remove viewA - OK
#3 Add viewB - OK
#4 Remove viewB - OK
#5 add viewA - Getting ERROR below
Please advice.
Thank you
-
{"Specified element is already the logical child of another element. Disconnect it first."}
-
   at System.Windows.FrameworkElement.ChangeLogicalParent(DependencyObject newParent)
   at System.Windows.FrameworkElement.AddLogicalChild(Object child)
   at DevExpress.Xpf.Docking.LayoutPanel.OnControlPropertyChanged(UIElement control, UIElement oldControl)
   at DevExpress.Xpf.Docking.LayoutPanel.OnControlChanged(UIElement control, UIElement oldControl)
   at DevExpress.Xpf.Docking.LayoutPanel.<.cctor>b__1(DependencyObject dObj, DependencyPropertyChangedEventArgs e)
   at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
   at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
   at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
...

Added By: NP23 at: 7/29/2013 12:03:02 PM    

The Remove event is not handled in the documentgroup adapter which does not reclaim the memory when tab is closed.

Added By: Simon Cui 1 at: 8/12/2013 9:13:37 AM    

Hide the leftregion, the navbar be removed, and hide leftregin again, throw error.

Added By: Sergey Wereteychenko at: 9/3/2013 12:27:27 AM    

Why this example is so bugged?
After detaching a panel - disappears a content, please try detach Toolbox...
And why this example craches every time, when attach-detach event happening...

Please, supply Working example.

Added By: Sergey Wereteychenko at: 9/3/2013 12:36:20 AM    

private void OnItemsCollectionChanged(IRegion region, LayoutGroup regionTarget, object sender, NotifyCollectionChangedEventArgs e)
        {
            if (lockItemsChanged)
            {
                return;
            }
            if (e.Action == NotifyCollectionChangedAction.Remove)
            {
                lockViewsChanged = true;
                var lp = (LayoutPanel)e.OldItems[0];
                var view = lp.Content;
                //lp.Content = null;
                region.Remove(view);
                lockViewsChanged = false;
            }
        }

Cause of removing content is "lp.Content = null;" row...
Why was existing this row in example?

Added By: NP23 at: 11/5/2013 11:02:15 AM    

Can you complete the code for remove action. We have something as below to remove any tabs that are floating or in the default layout group. it does not find tabs in newly created layout groups.

  case NotifyCollectionChangedAction.Remove:
                    List<DocumentPanel> panelToRemove = new List<DocumentPanel>();
                    List<FloatGroup> floatGroupToRemove = new List<FloatGroup>();
                    DockLayoutManager managerRemove = regionTarget.GetDockLayoutManager();
                    foreach (DocumentPanel panel in regionTarget.Items)
                    {
                        foreach (IPanelInfo oldItem in e.OldItems)
                        {
                            if (panel.Caption.Equals(oldItem.Title))
                            {
                                panelToRemove.Add(panel);
                            }
                        }
                    }

                    foreach (DocumentPanel pnl in panelToRemove)
                    {
                        regionTarget.Items.Remove(pnl);
                    }

                    panelToRemove.Clear();

                    foreach (var floatGroup in managerRemove.FloatGroups)
                    {
                        foreach (DocumentPanel panel in floatGroup.Items)
                        {
                            foreach (IPanelInfo oldItem in e.OldItems)
                            {
                                if (panel.Caption.Equals(oldItem.Title))
                                {
                                    panelToRemove.Add(panel);
                                }
                            }
                        }

                        foreach (DocumentPanel pnl in panelToRemove)
                        {
                            floatGroup.Items.Remove(pnl);
                        }

                        if (floatGroup.Items.Count == 0 )
                        {
                            floatGroupToRemove.Add(floatGroup);
                        }
                    }

                    foreach (FloatGroup floatGroup in floatGroupToRemove)
                    {
                        managerRemove.FloatGroups.Remove(floatGroup);
                    }

                    break;

Added By: Artem Dubenko 2 at: 8/6/2015 12:54:59 PM    

Unfortunately this example doesn't support selection/activation of the views. A call to IRegion.Activate(view) will have no effect.


Viewing all articles
Browse latest Browse all 7205

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>