Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Application must be instantiated before call to window constructor due to resources in App.xaml #41

Closed
cmeeren opened this issue Aug 2, 2018 · 3 comments

Comments

@cmeeren
Copy link
Member

cmeeren commented Aug 2, 2018

When using Program.runWindow, the window must necessarily be instantiated first. Since Application isn't instantiated before calling runWindow, I get the following exception on the InitializeComponent() call in the window constructor:

Exception: Cannot find resource named 'MaterialDesignMultiFloatingActionAccentPopupBox'. Resource names are case sensitive.

This error occurs because the resource in question is defined in my App.xaml:

<Application.Resources>
  <ResourceDictionary>
    <ResourceDictionary.MergedDictionaries>
      <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Light.xaml" />
      <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
      <ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Primary/MaterialDesignColor.Blue.xaml" />
      <ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.Lime.xaml" />
      <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.PopupBox.xaml" />
    </ResourceDictionary.MergedDictionaries>
  </ResourceDictionary>
</Application.Resources>

Since this is not instantiated/loaded before the window is initialized, I am unable to initialize my main window to start the app.

What is the best way to solve this? Is there something I can do, or must this be fixed in Elmish.WPF?

@cmeeren cmeeren changed the title Window XAML fails to initialize because App is not initialized Application must be instantiated before call to window constructor due to resources in App.xaml Aug 2, 2018
@cmeeren
Copy link
Member Author

cmeeren commented Aug 2, 2018

One workaround is of course to define the resources in all XAML files, but that's a horrible solution for obvious reasons. Surely there must be some way to use application-wide resources when using Elmish.WPF?

If this is indeed currently impossible, the fix could be as simple as adding a function runWithWindow that instead of a Window takes unit -> Window, and use this in Elmish.WPF.Program._run, and instantiate Application before instantiating the window. (Though if it's impossible to use resources in App.xaml with Elmish.WPF, I'd argue that this should be the default and only behavior and that runWindow should be changed.)

@cmeeren
Copy link
Member Author

cmeeren commented Aug 3, 2018

In fact, I see that Elmish.WPF calls Application() directly and doesn't use my custom Application subclass, which contains overrides for OnStartup etc. Is there any way to tell Elmish.WPF to use a custom Application class? If not, could this be implemented, and are there any other ways to do OnStartup and similar stuff?

@cmeeren
Copy link
Member Author

cmeeren commented Sep 1, 2018

Closed by #48

@cmeeren cmeeren closed this as completed Sep 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant