Skip to content

Commit

Permalink
Merge pull request #2829 from telerik/new-kb-kb-docking-invalidoperat…
Browse files Browse the repository at this point in the history
…ionexception-input-bindings-11ad6da4d2b343fba04661649330ed9b

Added new kb article kb-docking-invalidoperationexception-input-bindings
  • Loading branch information
StenlyGrigorov authored Feb 28, 2024
2 parents 96dbeb6 + 4a84f79 commit ae171c0
Showing 1 changed file with 50 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
title: Calling thread cannot access this object when opening RadDocking on another UI thread
type: how-to
page_title: InvalidOperationException is thrown when showing Docking on separate thread.
description: "The calling thread cannot access this object because a different thread owns it, when RadDocking is started on a new UI thread."
slug: kb-docking-invalidoperationexception-input-bindings
tags: raddocking, multiple-threads, exception, thread
res_type: kb
---

# Environment
| Product | RadDocking for WPF |
| ------- | ----------------- |
| Version | 2019.2.618 |

## Description

`InvalidOperationException` is thrown when `RadDocking` is hosted in a window that can be opened on separate UI threads.

The exception message is: *"The calling thread cannot access this object because a different thread owns it."*

## Solution

This happens because of a `MouseBinding` defined in the `InputBindings` collection of one of the `RadDocking` visuals (the `PaneHeader` element).

To avoid the issue, you can add a new `Style` for the `PaneHeader` element in the Resources of the window that opens on the new UI thread.

#### __[XAML]__
{{region kb-docking-invalidoperationexception-input-bindings-0}}
<UserControl.Resources>
<!--If you use NoXaml dlls please add BasedOn="{StaticResource PaneHeaderStyle}" to the Style object. For example: -->
<!--<Style TargetType="telerik:PaneHeader" BasedOn="{StaticResource PaneHeaderStyle}" >-->
<Style TargetType="telerik:PaneHeader">
<Setter Property="telerik:InputBindingsManager.InputBindings">
<Setter.Value>
<InputBindingCollection>
<MouseBinding Command="telerikDocking:RadDockingCommands.PaneHeaderMenuOpen">
<MouseBinding.Gesture>
<MouseGesture MouseAction="RightClick" />
</MouseBinding.Gesture>
</MouseBinding>
</InputBindingCollection>
</Setter.Value>
</Setter>
</Style>
</UserControl.Resources>
{{endregion}}

In some cases, you may need to merge this `Style` in the `Resources` of the opened `ToolWindow`. To do this, you can use the `ToolWindowCreated` event of `RadDocking`, where you can access the `Resources` of the window in code-behind.

0 comments on commit ae171c0

Please sign in to comment.