Description
Background:
WPF's theme assemblies (PresentationFramework.Aero, PresentationFramework.Aero2, PresentationFramework.AeroLite, PresentationFramework.Classic, PresentationFramework.Luna and PresentationFramework.Royale) expose the same types.
For e.g., DataGridHeaderBorder.
These assemblies can be used in two ways.
Typically, they are used as resource assemblies. i.e., they are not referenced from the project, and instead, XAML resources within them are consumed as resources using <ResourceDictionary ..>. When used this way, all of these assemblies can (and often are) used in to supply themes contextually (i.e., depending on the system theme, for e.g., or some other user preference).
Less commonly, they are directly referenced and their types are either consumed in XAML or directly in code. When used this way, only one assembly can be referenced directly. If more than one assembly needs to be referenced, namespace aliasing has to be used.
Problem:
The current SDK/FrameworkReference design in .NET Core always enables references to each of these assemblies. This makes them virtually unusable. We need a better scheme/solution.
Related:
- Support WPF and WinForms specific FrameworkReferences via Profiles #746
- WPF Theme Assemblies are not usable under the current FrameworkReference design sdk#3265
- Support WPF and WindowsForms-specific FrameworkReferences via profiles sdk#3259
Note:
Part of the solution lies in the SDK, and part of the solution would likely have to be implemented in Microsoft.NET.Sdk.WindowsDesktop targets.
Activity
Nirmal4G commentedon May 26, 2019
This is a blocker for me too!
Can we use the exisiting
PackageReferencefor the Theme assemblies instead ofFrameworkReference?vatsan-madhavan commentedon May 27, 2019
@Nirmal4G, Can you outline your exact scenario?
Specifically, what are you trying to do, and what scenario related to
PresentationFramework.*theme assemblies is failing in .NET Core that used to work in .NET Framework?vatsan-madhavan commentedon Jun 20, 2019
This is not a bug in WPF itself, and the solution will come from dotnet/sdk#3265.
Removing label:bug and marking it as lable:tracking_external_issue
vatsan-madhavan commentedon Nov 18, 2019
We don't expect to fix this in the SDK in 3.1 timeframe. We are suggesting the following target as a workaround for accessing WPF's theme assembly types from C# projects.
We will revisit this in .NET 5 if there is sufficient interest.
Nirmal4G commentedon Nov 19, 2019
What do you mean by sufficient interest?
vatsan-madhavan commentedon Nov 19, 2019
Please continue posting here about your scenarios/use-cases and migration problems.
We currently think that almost all applications should be able to workaround the current SDK design to access theme assembly types. If the feedback here tells us otherwise, we will work with the SDK team to re-think our approach.
Nirmal4G commentedon Nov 20, 2019
OK. Will do.
We have some tools that uses theming. I'll try to migrate them, and see what works.
Thanks so much.
gulbanana commentedon Jan 10, 2020
I have this problem in a control library. I use ButtonChrome and DataGridHeaderBorder to create aero-like controls, which means direct-referencing a theme assembly. The target-based workaround works for me when targetting netcoreapp3.1, but not when my TargetFramework is net472.
vatsan-madhavan commentedon Jan 11, 2020
You don't need this workaround for net472 - references for .NET Framework are always obtained using
Referenceitems. If you are using SDK style projects, we just pre-populate some standard WPF and WinForms references, but you have to add additional references on your own in the project file. And if you are multi-targeting both netcoreapp3.1 and net472, then you have to take care to condition those additionalReferenceitems for just .NET Framework Builds.This is how we do it for common references:
wpf/packaging/Microsoft.NET.Sdk.WindowsDesktop/targets/Microsoft.NET.Sdk.WindowsDesktop.props
Lines 85 to 145 in 52fc7fa
gulbanana commentedon Jan 11, 2020
i see, so when using the SDK to build for netfx it's using the existing assemblies from .net framework rather than new copies delivered with the sdk?
vatsan-madhavan commentedon Jan 13, 2020
Correct. Which means that if you target net4xy, you'll need to have .NET 4.X.Y targeting pack/developer pack installed (somehow).
The SDK that provides support for SDK style projects for WPF/WinForms is a .NET Core SDK; it supports .NET Framework targeting to enable migration (from netfx to netcore) scenarios - our primary goal was not about delivering a new/improved feature (namely SDK style project support) for WPF/WinForms on .NET Framework, and so we did not re-package and ship ref-assemblies for .NET Framework along with the .NET Core 3.0/.NET Core 3.1 SDK. This is not planned for .NET 5 either.
gulbanana commentedon Jan 14, 2020
Migration is exactly why I'm using multitargeting. Thanks for the explanation, as long as it can be made to work that's good enough (and using
<Reference>conditional on TFM does work).