Closed rabanti-github closed 3 years ago
It seems like the way your Bootstrap
is implemented results in an application without application resources.
Although you specified it correctly like this:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/AdonisUI;component/ColorSchemes/Light.xaml"/>
<ResourceDictionary Source="pack://application:,,,/AdonisUI.ClassicTheme;component/Resources.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
... it seems to be ignored somehow. That's why the window is missing its whole style.
I found 2 solutions to fix this.
Option 1 Move those resources to your window class instead of the app. This has the disadvantage that you need to include the resources for every window class you might have.
Option 2
Remove your Bootstrap
class and create the window manually in App.xaml.cs
like so:
protected override void OnStartup(StartupEventArgs e)
{
MainWindow window = new MainWindow();
window.Show();
}
This would be my recommended way because it seems weird that you have two classes inheriting from Application
anyway.
Option 2 is a very nice and easy solution. Thank you.
App.xaml.cs:
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
MainWindow window = new TestApp.MainWindow();
window.Show();
}
}
MainWindow.xaml.cs (one additional event handler and a property):
private void EN_Button_Click(object sender, RoutedEventArgs e)
{
HandleLocaleChange = true;
CurrentLocale = "en";
Close();
}
private void JP_Button_Click(object sender, RoutedEventArgs e)
{
HandleLocaleChange = true;
CurrentLocale = "ja";
Close();
}
public bool HandleLocaleChange { get; set; };
private void AdonisWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
if (!string.IsNullOrEmpty(this.CurrentLocale) && HandleLocaleChange)
{
string lang = this.CurrentLocale;
Thread.CurrentThread.CurrentUICulture = new CultureInfo(lang);
MainWindow window = new TestApp.MainWindow();
window.Show();
}
else
{
App.Current.Shutdown();
}
}
I try to implement a locale changer, based on an old stack overflow article (https://stackoverflow.com/a/55000619) . In this approach, the main window is started programmatically, using threading, and not using the ‘StartupUri’ attribute in App.xaml.
However, starting the application this way, seems to hide the title bar (no title, no buttons). Furthermore, the color schemes like DarkColorScheme seems not to work anymore.
What is the correct way to instantiate a AdonisWindow programmatically, when not using App.xaml as start object?
See attached sample project. TestApp.zip Thank you in advance.