Using Windows.Application.Current.Dispatcher.Invoke in a wpf class library

jacky Perpète 41 Reputation points

In WPF, in a class library, I use the Windows.Application.Current.Dispatcher.Invoke method to reference the window that contains the controls and my class.

To use this method, I added the PresentationFramework.dll and WindowsBase.dll references to the project.

It works perfectly.

The only problem, since these dlls are referenced to a folder related to the .net version, if I change the .net version, I have to change the dll references again.

Here is an example of the dlls folder for version .net 7.0.10 :

C:\Program Files\dotnet\packs\Microsoft.WindowsDesktop.App.Ref\7.0.10\ref\net7.0\PresentationFramework.dll.

Is there a solution to avoid this problem?

Is there another method in wpf to not use these dlls?

Microsoft Technologies based on the .NET software framework.
3,454 questions
Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,686 questions
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,369 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce ( 57,731 Reputation points

    You just build a multi target library.

    note: I think it’s a poor design for the library to know about calling back to the ui thread.

    0 comments No comments