Prism Navigation - Title not showing up in document tab

Docking/MDI for WPF Forum

Posted 7 years ago by Khalid Razak
Version: 17.1.0650
Avatar

Hello,
I'm using a sample Prism Navigation project (View-Switching Navigation_Desktop_Unity) from Microsoft and I was trying to integrate docking from ActiPro.
I cannot figure out why the tabs for my documents that I'm creating are not displaying the title.
Below is a snippet from the Shell.xaml.

<docking:DockSite Grid.Column="1" Grid.Row="2" prism:RegionManager.RegionName="MainContentRegion" CanDocumentWindowsFloat="True" CanDocumentWindowsClose="False">
   <docking:Workspace>
         <docking:TabbedMdiHost />
    </docking:Workspace>
</docking:DockSite>

There are three views that can be displayed in the MainContentRegion:
CalendarView
ContactsView
InboxView

The corresponding viewModels are:
CalendarViewModel
ContactsViewModel
InboxViewModel

All the viewmodels inherit from DockingItemViewModelBase which has a "Title" property that is bound to the ActiPro "DockingWindow.TitleProperty" property.
I'm setting the "Title" property in the constructor of my viewModels, however, the title is never displayed on the document tab for any of the views.
  Please advise.

Thanks,
Khalid

Comments (3)

Posted 7 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Khalid,

It should be working fine if the binding is successfully being placed on the Title property.  I would double check the the Title value is actually flowing through the binding once you set it, and investigate that area of your code.

If you can't figure it out, please make a new simple sample project that shows it happening and email that to our support address and we'll have a look.  Please reference this thread in your email and rename the .zip file extension so it doesn't get spam blocked.


Actipro Software Support

Posted 7 years ago by Khalid Razak
Avatar

Hello,
So the issue was that I was never registering any of the document viewmodels. I was registering navigation view items in my modules. These were buttons that were in a region called the "MainNavigationRegion". If I clicked any of those buttons, the callback for the current navigation item view called the Prism.Regions.RegionManager "RequestNavigate” to the “MainContentRegion” region with one of the views listed below:
CalendarView
ContactsView
InboxView


Below shows the registration of the Calendar navigation item:
this.regionManager.RegisterViewWithRegion(RegionNames.MainNavigationRegion, typeof(CalendarNavigationItemView));

When this navigation button item was clicked, the following callback code was executed:

private static Uri calendarViewUri = new Uri("CalendarView", UriKind.Relative);
this.regionManager.RequestNavigate(RegionNames.MainContentRegion, calendarViewUri);

The CalendarView constructor took a CalendarViewModel (inherits from DockingItemViewModelBase class) type as a parameter which was resolved using Unity dependency injection. In the viewmodel is where I set the title property.


After the RequestNavigate to CalendarView was called, this caused the callback method, “OnDockSiteWindowRegistered” method (sample ActiPro code) to be called. In this method, the PrepareContainerBindings was never getting called since it was expecting a view model. I’ve since modified the method to obtain the view model from the view’s datacontext.


private void OnDockSiteWindowRegistered(object sender, DockingWindowEventArgs e) {
if (!this.IsDockingWindowAValidContainer(e))
return;
// Bind to the view model and open the window
var viewModel = e.Window.DataContext as DockingItemViewModelBase;
if (null == viewModel)
{
var view = e.Window.DataContext as UserControl;
viewModel = view.DataContext as DockingItemViewModelBase;
}
if (viewModel != null)
e.Window.PrepareContainerBindings(viewModel);
}

This has fixed the problem, but I just wanted to make sure that this was the most appropriate way to resolve the issue.

Thanks.

Posted 7 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

While that may work around things here, a lot of the logic for our Prism example is focused on having view models be what is registered with the region instead of views.  Our design will kick in our logic for auto generating docking window "containers" for the view model and you can assign a unique view for each view model type if you wish.  If you are using view models with your views, then I might suggest you consider switching to that setup instead.

You worked around things like PrepareContainerBindings but I fear that things like IsDockingWindowAValidContainer and other areas might fail checks they are expecting to pass if you do things differently.


Actipro Software Support

The latest build of this product (v24.1.1) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.