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

jacky Perpète 81 Reputation points
2023-10-22T15:05:08.2133333+00:00

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?

.NET
.NET
Microsoft Technologies based on the .NET software framework.
4,061 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,817 questions
C#
C#
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.
11,227 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 69,886 Reputation points
    2023-10-22T22:04:32.06+00:00

    You just build a multi target library.

    https://learn.microsoft.com/en-us/nuget/create-packages/multiple-target-frameworks-project-file

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

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.