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

jacky Perpète 41 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.
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
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.
10,369 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 57,731 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