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.04k stars 667 forks source link

Option to disable the Application.Current #1081

Closed ricaun closed 1 month ago

ricaun commented 1 month ago

Is your feature request related to a problem? Please describe

Hello, last year I introduce the UiApplication to fix the issue when the Application.Current was null.

Now I have a different problem, the Application.Current exist but I'm not the owner, I still don't have access to the App.xaml.

The ApplicationThemeManager.Apply(this); is not gonna work because the Application.Current exist and don't have the styles.

Describe the solution you'd like

A way to fix that would be to add a option in the UiApplication to set the System.Windows.Application manually as null.

UiApplication.Current.SetApplication(null);
// or
UiApplication.Current.SetApplication(Application.Current);

and

public SetApplication(Application application)
{
    _application = application;
}

There is another option as well to check if the Application.Current contain the the basic resources style, if does not contain any resource means is not the Application owner and assumes that is running outside of the desktop app context.

I like the second option.

Describe alternatives you've considered

I gonna try to create a pr with the second option to disable the Application.Current if does not have any sytle related to the Wpf.UI

Additional context

This issue is related for Revit 2025 plugins.

This happens if I inject the resources in the Application.Current, breaks some ui from other windows. 😅 Wpf UI - Revit 2025 - 2024-05-09 17-56-39