Reputation: 2713
In my WPF application, I define a Style
in my App.xaml
and use it on other pages. But I want to compile my project into a .dll which requires me to delete App.xaml
. So I need to place my Style
somewhere else (preferably in a global place, not in every page that I make). Where can I put it and how can I use it?
I'm using MvvmCross by the way, but I don't think that's relevant.
Upvotes: 0
Views: 44
Reputation: 1479
For global declarations, if you see the generated cs file for App.Xaml, you will see something like windowsForm's Program.cs file (Mixed with a Form partial class Codes).
here is a Part of this file: (App.i.g.cs)
public void InitializeComponent() {
if (_contentLoaded) {
return;
}
_contentLoaded = true;
#line 7 "..\..\App.xaml"
this.StartupUri = new System.Uri("MainWindow.xaml", System.UriKind.Relative);
#line default
#line hidden
System.Uri resourceLocater = new System.Uri("/WpfPlayground;component/app.xaml", System.UriKind.Relative);
#line 1 "..\..\App.xaml"
System.Windows.Application.LoadComponent(this, resourceLocater);
#line default
#line hidden
}
Actually below line will forces the application to use your specific resouceDictionary file as a Global ResourceDictionary.
System.Windows.Application.LoadComponent(this, resourceLocater);
If you create a file that conforms App.xaml file (As you know this is the Main Entry-point of your EXE file), there will be no need to be depend on this file.
Note: App.i.g.cs is a AutoGenerated and you must conform the App.XAML rules.
Upvotes: 0
Reputation: 2127
Basically you create a new xaml anywhere you feel appropriate that contains <ResourceDictionary>
and then you can load these Resource dictionaries where ever you want like:
<Page.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="myresourcedictionary.xaml"/>
<ResourceDictionary Source="myresourcedictionary2.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Page.Resources>
More details here
Upvotes: 1