DocumentHost & Prism Region

52 posts, 0 answers
  1. esha aftab
    esha aftab avatar
    6 posts
    Member since:
    Apr 2010

    Posted 21 May 2010 Link to this post

    Hi,

    I was trying to use the method of Regions:RegionManager.RegionManager="{Binding Path=RegionManager}" as described in in one of the posts but could not get it right. Instead I'm getting an error on Shell Initialization :
    "Invalid attribute value {Binding Path=(RegionManager)} for property RegionManager.RegionManager."
    Can anyone help me with this issue. I need urgent solution to it. Is there a sample I can refer to, to resolve my problem?
  2. Miroslav Nedyalkov
    Admin
    Miroslav Nedyalkov avatar
    1718 posts

    Posted 25 May 2010 Link to this post

    Hi Esha,

     Did you try the work-around provided by Justin?

    All the best,
    Miroslav Nedyalkov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. esha aftab
    esha aftab avatar
    6 posts
    Member since:
    Apr 2010

    Posted 26 May 2010 Link to this post

    I do not understand the idea given in Justin's post. How do I get _documentHost, and I'm not familiar with the use of SetValueMethod. Canyou please elaborate that statement a little.

    Thanks in advance.
  4. Justin Brown
    Justin Brown avatar
    3 posts
    Member since:
    Nov 2009

    Posted 26 May 2010 Link to this post

    Sorry, perhaps my post was a little too succint. Here is the example XAML:

     

            <telerikDocking:RadDocking x:Name="_mainDock" Grid.Row="1">  
                <telerikDocking:RadDocking.DocumentHost> 
                    <telerikDocking:RadSplitContainer x:Name="_documentHost" telerikDocking:RadDocking.FloatingSize="1000,700">  
                    ...  
                    </telerikDocking:RadSplitContainer> 
                </telerikDocking:RadDocking.DocumentHost> 
     
                <telerikDocking:RadSplitContainer InitialPosition="DockedLeft">  
                    ...  
                </telerikDocking:RadSplitContainer> 
     
                <telerikDocking:RadSplitContainer InitialPosition="DockedBottom">  
                    ...  
                </telerikDocking:RadSplitContainer> 
     
            </telerikDocking:RadDocking> 
     

    And here is the example code in the codebehind file:

        public partial class Shell : UserControl  
        {  
            public Shell(IRegionManager regionManager)  
            {  
                InitializeComponent();  
     
                _documentHost.SetValue(RegionManager.RegionManagerProperty, regionManager);  
            }  
        ...  
        }  
     
     

    Hopefully that makes it clearer for you...

  5. esha aftab
    esha aftab avatar
    6 posts
    Member since:
    Apr 2010

    Posted 27 May 2010 Link to this post

    Thank you so much. It definitely did help. =)
  6. Wendell
    Wendell avatar
    2 posts
    Member since:
    Dec 2010

    Posted 25 Dec 2010 Link to this post

    Hi,

    I've converted this solution into an xbap solution. The mainregion is not being loaded into the regionmanager and throws a region not found exception while the code is exactly the same as the desktop one which works perfectly. Am I missing something? Any help will be appreciated

    It throws the following exception:

    System.Windows.Markup.XamlParseException occurred
      Message='The invocation of the constructor on type 'RadDockingAndPRISM_XBAP.Shell' that matches the specified binding constraints threw an exception.' Line number '5' and line position '4'.
      Source=PresentationFramework
      LineNumber=5
      LinePosition=4
      StackTrace:
           at System.Windows.Markup.XamlReader.RewrapException(Exception e, IXamlLineInfo lineInfo, Uri baseUri)
      InnerException: Microsoft.Practices.Composite.Modularity.ModuleInitializeException
           Message=An exception occurred while initializing module 'ModuleB'.
        - The exception message was: The region manager does not contain the MainRegion region.
        - The Assembly that the module was trying to be loaded from was:ModuleB, 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.
     
           Source=Microsoft.Practices.Composite
           ModuleName=ModuleB
           StackTrace:
                at Microsoft.Practices.Composite.Modularity.ModuleInitializer.HandleModuleInitializationError(ModuleInfo moduleInfo, String assemblyName, Exception exception)
                at Microsoft.Practices.Composite.Modularity.ModuleInitializer.Initialize(ModuleInfo moduleInfo)
                at Microsoft.Practices.Composite.Modularity.ModuleManager.InitializeModule(ModuleInfo moduleInfo)
                at Microsoft.Practices.Composite.Modularity.ModuleManager.LoadModulesThatAreReadyForLoad()
                at Microsoft.Practices.Composite.Modularity.ModuleManager.LoadModuleTypes(IEnumerable`1 moduleInfos)
                at Microsoft.Practices.Composite.Modularity.ModuleManager.LoadModulesWhenAvailable()
                at Microsoft.Practices.Composite.Modularity.ModuleManager.Run()
                at Microsoft.Practices.Composite.UnityExtensions.UnityBootstrapper.InitializeModules()
                at Microsoft.Practices.Composite.UnityExtensions.UnityBootstrapper.Run(Boolean runWithDefaultConfiguration)
                at Microsoft.Practices.Composite.UnityExtensions.UnityBootstrapper.Run()
                at RadDockingAndPRISM_XBAP.Shell..ctor() in E:\Carinthian.Blue\Concepts\DockingAndPrism\RadDockingAndPRISM_XBAP\Shell.xaml.cs:line 12
           InnerException: System.Collections.Generic.KeyNotFoundException
                Message=The region manager does not contain the MainRegion region.
                Source=Microsoft.Practices.Composite.Presentation
                StackTrace:
                     at Microsoft.Practices.Composite.Presentation.Regions.RegionManager.RegionCollection.get_Item(String regionName)
                     at ModuleB.ModuleB.Initialize() in E:\Carinthian.Blue\Concepts\DockingAndPrism\ModuleB\ModuleB.cs:line 21
                     at Microsoft.Practices.Composite.Modularity.ModuleInitializer.Initialize(ModuleInfo moduleInfo)
                InnerException:
  7. Davin
    Davin avatar
    2 posts
    Member since:
    Sep 2010

    Posted 21 Jan 2011 Link to this post

    I have been following this thread and a few others on prism, so far I have gotten through a few issues but am stumped on this one.  I have the shell found below which loads fine.
    <telerikDocking:RadDocking x:Name="radDocking1" Grid.Row="1" AllowUnsafeMode="True" cal:RegionManager.RegionManager="{Binding Path=RegionManager}">
                <telerikDocking:RadDocking.DocumentHost >
                    <telerikDocking:RadSplitContainer x:Name="_documentHost">
                        <telerikDocking:RadPaneGroup x:Name="radPaneGroup" cal:RegionManager.RegionName="{x:Static infra:RegionNames.MainRegion}"  cal:RegionManager.RegionManager="{Binding Path=RegionManager}">
                            <telerikDocking:RadDocumentPane Title="Home"  CanFloat="False" CanUserClose="True"  />
                        </telerikDocking:RadPaneGroup>
                    </telerikDocking:RadSplitContainer>
                </telerikDocking:RadDocking.DocumentHost>
                <telerikDocking:RadSplitContainer InitialPosition="DockedLeft">
                    <telerikDocking:RadPaneGroup>
                        <telerikDocking:RadPane Header="Section"  HeaderTemplate="{StaticResource SectionHeaderTemplate}" IsPinned="False" CanUserClose="True" cal:RegionManager.RegionName="LeftRegion" />
                    </telerikDocking:RadPaneGroup>
                </telerikDocking:RadSplitContainer>
                <telerikDocking:RadSplitContainer InitialPosition="DockedRight">
                    <telerikDocking:RadPaneGroup>
                        <telerikDocking:RadPane  HeaderTemplate="{StaticResource HelpHeaderTemplate}" Header="Help" CanUserClose="True" CanFloat="True"  IsPinned="False"  cal:RegionManager.RegionName="RightRegion" />
                    </telerikDocking:RadPaneGroup>
                </telerikDocking:RadSplitContainer>
            </telerikDocking:RadDocking>

    I am loading a view called View1 into the MainRegion as a doc pane.

    <telerikDocking:RadPane x:Class="View1"
            xmlns:telerikDocking="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Docking"
            xmlns:cal="http://www.codeplex.com/CompositeWPF"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Header="Search" x:Name="SearchTestView">
        <Grid>
            <TextBlock>testing 123</TextBlock>
        </Grid>
    </telerikDocking:RadPane>

    This all works but the problem lies in when I close the docpane (tab) there are issues reactivating it using the code below. It works the first time, but if I close the docpane again, they code runs without error but the view does not display..

    string viewName1 = "SearchTestView";
    IRegion detailsRegion1 = _regionManager.Regions["MainRegion"];
    object view1 = detailsRegion1.GetView(viewName1);
     
    if (view1 == null)
    {
          view1 = _container.Resolve<View1>();
          detailsRegion1.Add(view1, viewName1);
    }
    detailsRegion1.Activate(view1);

    Any help would be most appreciated. Thanks.
  8. George
    Admin
    George avatar
    1332 posts

    Posted 27 Jan 2011 Link to this post

    Hi Davin,

     
    We are not aware of such problem. Could you please give us more information about your scenario? Why do you need to close one and same pane several times ? Also, if you send us a running example it would be very helpful in further pinpointing the problem.

    Regards,
    George
    the Telerik team
    Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
  9. Davin
    Davin avatar
    2 posts
    Member since:
    Sep 2010

    Posted 27 Jan 2011 Link to this post

    My scenario is to load PRISM views into RadDocumentPanes.  Each view can be opened from the menu, and subsequently closed by the user (using the close X button in the corner of the RadDocumentPane).

    I can't find the post that helped solve my solution right now but it seems that the PRISM framework is not handling the view name properly.  The post that I read described that the GetView prism function was not working correctly in actually finding the view name (x:Name).

    detailsRegion1.GetView("MyView");

    This code will return null even though I have specified x:Name="MyView"  in my prism view (RadDocumentPane).

    This could be more elegant code but for now this is how I got my menu button to re-load /open a RadDocumentPane view.
     
    bool found = false;
                foreach (RadPane pane in detailsRegion.ActiveViews)
                {
                    if (pane.Name == viewName)
                    {
                        found = true; break;
                    }
                }
      
                if (!found)
                {
                    object view = _container.Resolve<AssessmentSearchView>();
                    detailsRegion.Add(view, viewName);
                }

    For anyone interested (since I cound't find an example)  here is how I remove the view when the user clicks the close button on the RadDocumentPane.  This code is in my shell view where all the the rad docking controls are (also not that elegant right now).

    private void RadDocking_Close(object sender,  Telerik.Windows.Controls.Docking.StateChangeEventArgs e)
            {
              IRegion MainRegion = _RegionManager.Regions["MainRegion"];
                foreach (var pane in e.Panes)
                {
                    foreach (RadPane view in MainRegion.ActiveViews)
                    {
                        if (pane.Name == view.Name)
                            MainRegion.Remove(view);
                    }
                
            }

    So ...my initial problems are somewhat solved and seem to work but now I have a new problem which seems to be described in this logged issue and resolved but unscheduled.
    http://www.telerik.com/community/forums/wpf/docking/binding-fails-after-switching-between-tabbed-document-and-floating-mode-radpane.aspx
    http://www.telerik.com/support/pits.aspx#/public/wpf/3952
  10. Michael
    Michael avatar
    105 posts
    Member since:
    Nov 2010

    Posted 22 Feb 2011 Link to this post

    Please help im tearing my hair out with this one....

    I had this RadPaneGroupRegionAdapter working fine...then i started moving my reference dlls around...now I evidently moved somehting i shouldnt have and im getting the following errors on the line

    regiontarget.Items.Add(item);

    Items is the red squiggly error and it says:
    ItemCollection ItemsControl.Items
    C# Unknown member 'Items' of Telerik.Windows.COntrols.RadPaneGroup


    similarly for parent
    unknown member "Parent" of Telerik.Windows.Controls.radPane"


    i hate reference crap!!

    OK loaded it on my laptop and it now has the following error on RadPaneGroup within the " RegionAdapterBase<RadPaneGroup>

    stating that module "System.Windows" must be referenced

    ohhh help i do dislike references

  11. George
    Admin
    George avatar
    1332 posts

    Posted 28 Feb 2011 Link to this post

    Hello Michael,

    Please, clean the project,  remove the references, added them again, clean again and rebuild the project. Make sure you have added the following references in order to use the RadDocking controls:
    • Telerik.Windows.Controls
    • Telerik.Windows.Controls.Navigation
    • Telerik.Windows.Controls.Docking

    I hope this helps. 


     Best wishes,
    George
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
  12. Chris
    Chris avatar
    17 posts
    Member since:
    Nov 2009

    Posted 28 Feb 2011 Link to this post

    Hi,

    I am experiencing the same issue as discussed on http://compositewpf.codeplex.com/discussions/60215?ProjectName=compositewpf

    Unfortunately the above link does not provide a solution. 

    From what I understand the RegionManager walks the visual tree discovering regions that have been defined, however, it cannot access any controls located within the DocumentHost.

    Is it possible to define a region within a DocumentHost while using Prism with DI?

    Thanks heaps.
  13. George
    Admin
    George avatar
    1332 posts

    Posted 01 Mar 2011 Link to this post

    Hi Chris,

     
    We area aware of such problem with the regions, defined in the DocumentHost. Could you please specify do you use PRISM Unity or PRISM MEF?

    Greetings,
    George
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
  14. Chris
    Chris avatar
    17 posts
    Member since:
    Nov 2009

    Posted 01 Mar 2011 Link to this post

    Hi George,

    Thanks for the reply - we are using Unity

    Cheers
    Chris
  15. Patrick
    Patrick avatar
    11 posts
    Member since:
    Jun 2009

    Posted 01 Mar 2011 Link to this post

    Hi George,

    We are using Prism with Unity. Is there a way to make this work?

    Thanks heaps,
    Patrick.
  16. George
    Admin
    George avatar
    1332 posts

    Posted 02 Mar 2011 Link to this post

    Hello,

    The issue here is tightly related with the Prism framework and usage the RadPaneGroup in the DocumentHost as Region. If you remove the DocumentHost, everything works as expected. I would suggest you to use the RegionManager.SetRegionManager method to register the pane group as region. 

     

    Regards,
    George
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
  17. Tim
    Tim avatar
    85 posts
    Member since:
    Aug 2008

    Posted 02 Mar 2011 Link to this post

    I watch you guys struggling on this thread trying to fit your applications into the "box" of PRISM.  By doing this, you're always going to run into some 3rd party control or situation which doesn't fit into PRISM.  I learned a long time ago that it doesn't make sense to register a "Region" from your Modules.  Why does a Module have to know everything about the Shell's UI and have to know exactly where to put it's region?  I thought they always taught us in programming about "Seperation of Concerns".  Well, why are you coding Modules that are "concerned" about the responsibilities of the Shell!?  This make absolutely no sense and was the same issue when CAB came out about 8 years ago.  I can't post a "solution" to your problems, because you really need to restructure your applications to do PRISM "correctly".  If you're following PRISM "examples" online, then you're doing it wrong.

    We follow a different approach where the Shell manages all the interaction between it's 3rd party controls and Regions.  Module's "loosely" register themselves into the Shell by invoking a custom CompositePresentationEvent.  So, essentially, we never register "regions" with the DocumentHost.  The Shell takes care of creating and cleaning up the different Document Windows by creating a new Content element that the Module's multiple UIs get plugged into.  The modules know nothing about this and don't care.

    Hint / Example:
    eventAggregator.GetEvent<ShellViewRegistrationEvent>().Publish(new ShellViewActivationEventArgs(...));

    In our framework, we can actually have other modules that use different 3rd party tools that know absolutely nothing about Telerik but at the same time can plug right into the Shell (again, because the Shell is driving everything).  Suffice it to say, I have yet to develop ANY custom RegionManagers for Telerik controls.  We have also been able to port our applications over to MEF fairly easily without affecting large chunks of code in the Modules.  Basically, only the Shell changes.
  18. Patrick
    Patrick avatar
    11 posts
    Member since:
    Jun 2009

    Posted 03 Mar 2011 Link to this post

    Hi George thanks for the response.

    One other question... how can you access the parent of a RadSplitContainer which is located within a DocumentHost?

    When a RadSplitContainer is located within a DocumentHost, the Parent property is null.

    Thanks heaps,
    Patrick.
  19. Alex Galie
    Alex Galie avatar
    22 posts
    Member since:
    Dec 2009

    Posted 04 Mar 2011 Link to this post

    Hi Chris and Patrick,

    The workaround I use for this (I've ran into the same issue) is to store a reference to the RegionManager in the shell's view model then bind it like this:

    ShellView.cs
    <telerikDocking:RadDocking>
                 
                <telerikDocking:RadDocking.DocumentHost>
                    <telerikDocking:RadSplitContainer x:Name="CenterContainer">
                        <telerikDocking:RadPaneGroup x:Name="MainRegion"
                            rgn:RegionManager.RegionManager="{Binding RegionManager}"
                            rgn:RegionManager.RegionName="{StaticResource MainRegion}">
                             
                        </telerikDocking:RadPaneGroup>
                    </telerikDocking:RadSplitContainer>
                </telerikDocking:RadDocking.DocumentHost>
     
    </telerikDocking:RadDocking>


    ShellViewModel.cs

    public class ShellViewModel : NotificationObject
    {
        public IRegionManager RegionManager { get; private set; }
     
        public ShellViewModel(IRegionManager regionManager)
        {
            RegionManager = regionManager;
        }
    }
  20. Wendell
    Wendell avatar
    2 posts
    Member since:
    Dec 2010

    Posted 17 Sep 2011 Link to this post

    Hmmm interesting, I see where you are going with this however i cannot get it to work. I get a xaml parse exception telling me that it cant find the MainRegion as a static resource. Is your example perhaps incomplete and you're not showing us how you implemented the MainRegion as a static resource???
  21. Alex Galie
    Alex Galie avatar
    22 posts
    Member since:
    Dec 2009

    Posted 17 Sep 2011 Link to this post

    Hi Wendell,

    Yes it's incomplete, I'm defining all string constants in code then add them as static resources at runtime via merged dictionaries. Here's how I do it:

    Constants class (each app module including shell could have one of these):

        public class ApplicationData
        {
            // Shell regions
            public const string RegionNavigationTop = "NavigationRegionTop";
            public const string RegionNavigationBottom = "NavigationRegionBottom";
            public const string RegionMain = "MainRegion";
            public const string RegionMenu = "RegionMenu";
            public const string RegionFloatingDockRight1 = "RegionFloatingDockRight1";
            public const string RegionFloatingDockRight2 = "RegionFloatingDockRight2";
            public const string RegionBottomPanel = "RegionBottomPanel";
    }

    An extension class that takes constants and adds them as static resources:

    public static class CommonExtensions
    {
        /// <summary>
        /// Builds a dictionary at runtime with string constants from the given type and merges it into the global application dictionary.
        /// </summary>
        /// <param name="Type"></param>
        public static void RegisterDictionaryLiterals(this Type Type)
        {
            var literals = Type.GetFields().Where(f =>
                f.IsPublic && f.IsLiteral &&
                (f.FieldType.Equals(typeof(string)) || f.FieldType.Equals(typeof(int)) || f.FieldType.Equals(typeof(double))));
     
            ResourceDictionary dict = new ResourceDictionary();
            foreach (FieldInfo literal in literals)
            {
                dict.Add(literal.Name, literal.GetRawConstantValue());
            }
            Application.Current.Resources.MergedDictionaries.Add(dict);
        }
    }

    Finally, in every module you register the constants (in ModuleInit.cs ctor or Application_Startup in shell):

    typeof(ApplicationData).RegisterDictionaryLiterals();
  22. Pramod
    Pramod avatar
    1 posts
    Member since:
    Oct 2011

    Posted 24 Nov 2011 Link to this post

    Thanks It worked for me...
Back to Top