This is a migrated thread and some comments may be shown as answers.

Trouble Adding RadDocking to RadTabControl or RadTabbedWindow DataTemplate

1 Answer 181 Views
Docking
This is a migrated thread and some comments may be shown as answers.
Tim
Top achievements
Rank 1
Tim asked on 09 Jan 2020, 10:54 PM

Hi,

We have a requirement to have multiple isolated work spaces in our application (which we originally planned to host in RadTabbedWindow tabs).

Each of these work spaces need to have their own RadDocking set up and be navigable.

We are using implicit datatemplates for our MVVM infrastructure and binding ContentControls to viewmodels at runtime and we are having issues with the TabControl/Window datatemplate and the RadDocking framework.

The problems we are having are as follows:
1) When we bind an ObservableCollection of ViewModels to the ItemsSource property of the RadTabControl/RadTabbedWindow and we try to set up RadDocking in the TabControl/Window's ContentTemplate, an exception gets thrown.

Here's our the code:

<telerik:RadTabControl ItemsSource="{Binding WorkspaceViewModels}"
                         x:Name="WorkspaceContainer"
                         ScrollMode="Viewport"
                         SupressSelectedContentTemplateReapplying="True"
                         IsContentPreserved="True">
    <!-- Event is only available with RadTabbedWindow
    <telerik:EventToCommandBehavior.EventBindings>
        <telerik:EventBinding EventName="AddingNewTab" Command="{Binding AddWorkspaceCommand}"/>
    </telerik:EventToCommandBehavior.EventBindings>-->
    <telerik:RadTabControl.ItemTemplate>
        <DataTemplate>
            <StackPanel>
                <TextBlock Text="{Binding Title}"/>
            </StackPanel>
        </DataTemplate>
    </telerik:RadTabControl.ItemTemplate>
    <telerik:RadTabControl.ContentTemplate>
        <DataTemplate>
            <telerik:RadDocking  BorderThickness="0" Padding="0">
                <telerik:RadDocking.DocumentHost>
                    <telerik:RadSplitContainer>
                        <telerik:RadPaneGroup x:Name="PrimaryPaneGroup">
                            <ContentPresenter Content="{Binding}"/>
                        </telerik:RadPaneGroup>
                    </telerik:RadSplitContainer>
                </telerik:RadDocking.DocumentHost>
            </telerik:RadDocking>
        </DataTemplate>
    </telerik:RadTabControl.ContentTemplate>
    <telerik:RadTabControl.ItemContainerStyle>
        <Style TargetType="telerik:RadTabItem">
            <Setter Property="MinHeight" Value="40" />
            <Setter Property="FontWeight" Value="Bold" />
            <Setter Property="PinButtonVisibility" Value="Visible" />
            <Setter Property="CloseButtonVisibility" Value="Visible"/>
            <Setter Property="IsSelected" Value="{Binding IsActiveWorkspace}" />
        </Style>
    </telerik:RadTabControl.ItemContainerStyle>
</telerik:RadTabControl>

And here's the exception that gets thrown is as follows:

System.NullReferenceException
  HResult=0x80004003
  Message=Object reference not set to an instance of an object.
  Source=Telerik.Windows.Controls.Docking
  StackTrace:
   at Telerik.Windows.Controls.RadPaneGroup.OnIsInDocumentHostChanged(Boolean oldValue, Boolean newValue)
   at Telerik.Windows.Controls.RadPaneGroup.Telerik.Windows.Controls.Docking.IDocumentHostAware.set_IsInDocumentHost(Boolean value)
   at Telerik.Windows.Controls.RadSplitContainer.PrepareContainerForItemOverride(DependencyObject element, Object item)
   at System.Windows.Controls.ItemsControl.MS.Internal.Controls.IGeneratorHost.PrepareItemContainer(DependencyObject container, Object item)
   at System.Windows.Controls.ItemContainerGenerator.System.Windows.Controls.Primitives.IItemContainerGenerator.PrepareItemContainer(DependencyObject container)
   at System.Windows.Controls.Panel.GenerateChildren()
   at System.Windows.Controls.Panel.EnsureGenerator()
   at System.Windows.Controls.Panel.get_InternalChildren()
   at Telerik.Windows.Controls.ProportionalStackPanel.MeasureOverride(Size availableSize)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint)
   at System.Windows.Controls.ItemsPresenter.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Controls.Border.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Controls.Grid.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Controls.Control.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint)
   at System.Windows.Controls.ContentPresenter.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Controls.Border.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Controls.Control.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at Telerik.Windows.Controls.RadDockPanel.MeasureOverride(Size availableSize)
   at Telerik.Windows.Controls.DockingPanel.MeasureOverride(Size availableSize)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at Telerik.Windows.Controls.RadDockPanel.MeasureOverride(Size availableSize)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Controls.Border.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Controls.Grid.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Controls.Control.MeasureOverride(Size constraint)
   at Telerik.Windows.Controls.RadDocking.MeasureOverride(Size availableSize)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint)
   at System.Windows.Controls.ContentPresenter.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Controls.Grid.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.ContextLayoutManager.UpdateLayout()
   at System.Windows.ContextLayoutManager.UpdateLayoutCallback(Object arg)
   at System.Windows.Media.MediaContext.InvokeOnRenderCallback.DoWork()
   at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()
   at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)
   at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget)
   at System.Windows.Media.MediaContext.Resize(ICompositionTarget resizedCompositionTarget)
   at System.Windows.Interop.HwndTarget.OnResize()
   at System.Windows.Interop.HwndTarget.HandleMessage(WindowMessage msg, IntPtr wparam, IntPtr lparam)
   at System.Windows.Interop.HwndSource.HwndTargetFilterMessage(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 System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)

2) We have found that we can fix this issue and prevent the NullReferenceException by modifying the code above and adding a RadTabItem wrapper to the ContentTemplate like this:

<telerik:RadTabControl.ContentTemplate>
            <DataTemplate DataType="{x:Type vms:WorkspaceViewModel}">
                <telerik:RadTabItem>
                    <telerik:RadDocking  BorderThickness="0" Padding="0">
                        <telerik:RadDocking.DocumentHost>
                            <telerik:RadSplitContainer>
                                <telerik:RadPaneGroup x:Name="PrimaryPaneGroup">
                                    <ContentPresenter Content="{Binding}"/>
                                </telerik:RadPaneGroup>
                            </telerik:RadSplitContainer>
                        </telerik:RadDocking.DocumentHost>
                    </telerik:RadDocking>
                </telerik:RadTabItem>
            </DataTemplate>
        </telerik:RadTabControl.ContentTemplate>


 The problem, however, is that this makes the entire central pane basically act like a button (see attached picture ), where hovering over the pane changes the color of the entire screen.

 Neither one of these gets us any closer to what we really need: a bindable RadTabbedWindow with a dynamic/templatable/bindable RadDocking setup on each tab.
 
 I would really appreciate any pointers or help on this!
 Thank you so much for your time.

 Tim

1 Answer, 1 is accepted

Sort by
0
Accepted
Dinko | Tech Support Engineer
Telerik team
answered on 14 Jan 2020, 10:52 AM

Hello Tim,

Thank you for the provided code snippet and image.

I was able to reproduce this behavior. The exception comes from the ContentPresenter placed inside the RadPaneGroup. If you remove it and place a RadPane, the exception is not raised anymore. But I am missing the whole picture here. May I ask you to elaborate more on your scenario. What functionality you are trying to achieve. If you want to place the RadDocking control inside the RadTabItem, you can use the Content property of the RadTabItem in the custom style. Check the attached project.

Regards,
Dinko
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Docking
Asked by
Tim
Top achievements
Rank 1
Answers by
Dinko | Tech Support Engineer
Telerik team
Share this question
or