How to use customized DocumentWindow/ToolWindow with MVVM?

Docking/MDI for WPF Forum

Posted 2 years ago by Yuki
Version: 21.1.3


I'm using Docking/MDI for WPF with MVVM. I want to customize DocumentWindow/ToolWindow. Could you please tell me correct way?

Blow is my sample source code.

public partial class CustomToolWindow : ToolWindow
    // Add custom property
	.... >

			TargetType="{x:Type sample:CustomToolWindow}">

			<Setter Property="XXX" Value="XXX" />

	<!-- DockSite -->
	<docking:DockSite x:Name="dockSite"
		ToolItemContainerStyle="{StaticResource CustomToolWindow}"
		ToolItemTemplateSelector="{StaticResource XXXX}"
		ToolItemsSource="{Binding XXXX}" >

				<docking:TabbedMdiHost />


When ItemViewModel is added to ToolItems, the following exception occurred.

Message='CustomToolWindow' TargetType は、要素 'ToolWindow' の型と一致しません。

⇒'CustomToolWindow' TargetType does not match type of element 'ToolWindow'.

  Message='CustomToolWindow' TargetType は、要素 'ToolWindow' の型と一致しません。
  スタック トレース:
   at System.Windows.Style.CheckTargetType(Object element)
   at System.Windows.StyleHelper.UpdateStyleCache(FrameworkElement fe, FrameworkContentElement fce, Style oldStyle, Style newStyle, Style& styleCache)
   at System.Windows.FrameworkElement.OnStyleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
   at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
   at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
   at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
   at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
   at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType, Boolean isInternal)
   at ActiproSoftware.Windows.Controls.Docking.DockSite.ApplyContainerStyle(Object item, DockingWindow container, StyleSelector styleSelector, Style style)
   at ActiproSoftware.Windows.Controls.Docking.DockSite.PrepareContainerForItemOverride(DockingWindow container, Object item, DockingWindowItemKind kind)
   at ActiproSoftware.Windows.Controls.Docking.DockSite.nnp(IList`1  , IList  , Int32  , DockingWindowItemKind  )
   at ActiproSoftware.Windows.Controls.Docking.DockSite.xnG(Object  , NotifyCollectionChangedEventArgs  )
   at System.Collections.ObjectModel.ObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
   at System.Collections.ObjectModel.ObservableCollection`1.InsertItem(Int32 index, T item)
   at System.Collections.ObjectModel.Collection`1.Add(T item)

[Modified 2 years ago]

Comments (3)

Answer - Posted 2 years ago by Actipro Software Support - Cleveland, OH, USA


If you are using the DockSite with a MVVM ToolItemsSource and you want to use a different container type, you need to have the DockSite generate that container type in place of ToolWindow, which it is going to do by default.  This documentation topic talks about MVVM usage.  DockSite is set up to work pretty much the same way a normal ItemsControl does in terms of container generation.

Specifically to use a different type based on ToolWindow, you'll have to override DockSite.GetContainerForItemOverride and have it return an instance of your CustomToolWindow type instead of ToolWindow.  That's why you are getting the type match exception for the Style.

Actipro Software Support

Posted 2 years ago by Yuki

Thank you very much for replying.

Exception was solved!

# I'm sorry that I have not read document well.

Ex.) My sample code

        /// <inheritdoc/>
        protected override ActiproSoftware.Windows.Controls.Docking.DockingWindow GetContainerForItemOverride(ActiproSoftware.Windows.Controls.Docking.DockingWindowItemKind kind)
            switch (kind)
                case ActiproSoftware.Windows.Controls.Docking.DockingWindowItemKind.Document:
                    return new CustomDocumentWindow();
                case ActiproSoftware.Windows.Controls.Docking.DockingWindowItemKind.Tool:
                    return new CustomToolWindow();
                    return new ActiproSoftware.Windows.Controls.Docking.DockingWindow();
Posted 2 years ago by Actipro Software Support - Cleveland, OH, USA


The only change I would make is return the result of the base method for the "default" case instead of making a new DockingWindow.

Actipro Software Support

The latest build of this product (v24.1.2) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.