Document default dock location

Docking/MDI for WPF Forum

Posted 3 years ago by Eric P
Version: 16.1.0632
Avatar

Up until now I have had one and only one Document in the DocumentItems collection. My MainWindow view is simply a Ribbon, DockSite, and a StatusBar. The DockSite is defined like the following. 

<docking:DockSite DocumentItemsSource={Binding DocumentItems”} 
                  DocumentItemContainerStyle=”{StaticResource DocumentItemStyle}”
                  ToolItemsSource=”{Binding ToolItems}”
                  ToolItemContainerStyle=”{StaticResource ToolItemStyle}”
  <docking:SplitContainer>
    <docking:Workspace>
      <docking:TabbedMdiHost />
    </docking:Workspace>
  </docking:SplitContainer>
</docking:DockSite>

Now I am trying to add multiple documents of two different types. I have two ViewModels, say MainDocumentViewModel and SecondaryDocumentViewModel both inherit from DocumentWindowViewModel which contains all of the properties like IsOpen, CanClose, etc. The MainDocumentViewModel gets created at startup and added to the DocumentItems collection and the SecondaryDocumentViewModel(s) get created upon user request (clicking a button).

When a SecondaryDocumentViewModel gets created I do not want it to be docked with the MainDocumentViewModel by default. I would like it to be docked below the MainDocumentViewModel. I believe this is called a Vertical Container? I know how to configure a ToolWindow to be docked right, left, bottom but how can I configure my SecondaryDocumentViewModel to dock below the main document if it’s the first secondary document and if there already a secondary document then the next secondary document will dock on top of the previous secondary document. I believe I can achieve the second part of this by using the WindowsGroupName. All my secondary document have the name WindowsGroupName but how to I get it setup the first time a secondary document is added?

Thanks,

   -eric

Comments (3)

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

Hi Eric,

For more complex default location specifications, you can handle the DockSite.WindowDefaultLocationRequested event.  That lets you dynamically pick a particular dock target and side that the document window should first open up next to.  You can add complex logic in there to determine what to do. 

There is a Default Locations QuickStart that shows off use of that event if you need a good example.


Actipro Software Support

Posted 3 years ago by Eric P
Avatar

Great. Thanks for the fast reply. So based on your suggestion I did the following in the code-behind.

private void dockSite_WindowDefaultLocationRequested(object sender, DockingWindowDefaultLocationEventArgs e){
  if (e.Target != null) { return; }
  if (e.Window.DataContext is SecondaryDocumentViewModel) {
    e.Target = dockSite.PrimaryDocument;
    e.Side = Side.Bottom;
  }
}

So this works for now but I think as our app gets more complicated I will have to check if the PrimaryDocument is null and check if its DataContext is of type MainDocumentViewModel.

Do you think there is any need to be able to put this in the VM vs. the code-behind? I tired using the Interactions XAML like the follwoing.

<i:Interaction.Triggers>
    <i:EventTrigger EventName="WindowDefaultLocationRequested">
        <i:InvokeCommandAction Command="{Binding Path=WindowDefaultLocationRequestedCommand}"/>
    </i:EventTrigger>
</i:Interaction.Triggers>

While this did execute the Command (a Prism DelegateCommand in my case) I was not able to figure out how to get the correct CommandParameter set. Just curious.

Thanks,

   -eric

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

Hi Eric,

I'm not sure interactions XAML will work well in this scenario.  You are probably better off handling it in the view's codebehind and making any queries into the VM from there as necessary.


Actipro Software Support

The latest build of this product (v2019.1 build 0681) 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.