lepoco / wpfui

WPF UI provides the Fluent experience in your known and loved WPF framework. Intuitive design, themes, navigation and new immersive controls. All natively and effortlessly.
https://wpfui.lepo.co
MIT License
7.14k stars 678 forks source link

UiApplication.Current to fix Application.Current when null. #837

Open ricaun opened 8 months ago

ricaun commented 8 months ago

Is your feature request related to a problem? Please describe

If the Application.Current is null the Wpf.Ui library does not work, too many Application.Current are hard coded.

This problem is related to #662 and #668

Describe the solution you'd like

A way to use the Wpf.Ui library even if the Application.Current is null.

Describe alternatives you've considered

I was experimenting with version 2.2.0 a way to fix the problem by swapping all the Application.Current to a custom class UiApplication.Current to manage the Resources from the Application.Current if not null or return the Resources from a static internal ResourceDictionary.

This approach gonna ensure that all the current implementations stay the same. The alternative ResourceDictionary gonna be used if the Application is null.

Here is a full repo with that implementation: https://github.com/ricaun/wpfui/tree/2.2.0-uiapplication

I created the project Wpf.Ui.SimpleConsoleDemo with a working implementation when Application.Current is null.

Additional context

Before creating a PR, I would like to discuss whether that approach makes sense to implement in the main library.

ricaun commented 8 months ago

I created a stable version to use inside Revit, here is a release with the custom package.

https://github.com/ricaun/wpfui/releases/tag/2.2.0-pre-revit

To apply the resource just use the Wpf.Ui.Appearance.Theme.Apply(this) after your InitializeComponent().

The assembly was changed to Revit.Wpf.Ui.2.2.0 to avoid conflicts with the original Wpf.Ui package.