I have a solution with 5 projects.
Library
Shell
App 1
App 2
App 3
The shell and the apps all depend on the library.
The Shell is the application that runs.
I'm pretty novice, but I've never dealt with multiple projects in a solution and now I have style issues.
My main styles for each app are in its app.xaml file however all 3 apps seem to use the style from the app.xaml of the Shell project.
I've tryied putting:
Library/Styles/app1_style
for each style and then referencing that style in the app.xaml of each app:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/Library;component/Styles/app1_Styles.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
This doesn't seem to work at all.
How can I :
Make sure I use each apps specific stylesheet when I run the shell project
Make sure they can also see these styles at design time.
(I've tried deleting styles from app.xaml and then at design time everything is default but at runtime it then uses the style sheets!)
Related
I'm working on an extension for Visual Studio and I'm currently looking at using WPF instead of Forms for the template wizard.
I've got it all working with Forms but I much prefer the look of and working with WPF, but I'm not sure if what I'm trying to do is possible - or how I should go about doing it properly.
My VSIX consists of your typical layout, it's a solution with 3 projects;
1. MyProjectTemplate (C# Project Template)
2. MyProjectVSX (C# VSIX Template)
3. MyWizardWPF (WPF App)
I'm also using MahApps.Metro to make it look a bit sleeker. Added (via NuGet) and referenced by both MyProjectVSX and MyWizardWPF.
And while it works - the WPF shows up when I go to create a template - it is completely and utterly missing any styles. It basically just looks like a Windows 95 application.
I'm assuming this is related to the App.xml and it being unable to locate it. But I'm at a complete loss at how to tie all of this together. I get a bunch of warnings that it was unable to find various style related things. For example;
System.Windows.ResourceDictionary Warning: 9 : Resource not found; ResourceKey='MahApps.Brushes.IdealForeground'
System.Windows.ResourceDictionary Warning: 9 : Resource not found; ResourceKey='MahApps.Brushes.ThemeForeground'
I've tried playing around with the ResourceDictionary URIs, copying the App.xml to my VSX project. Tried building it as a class library instead of an application but to no avail.
Is what I'm trying to achieve here feasible...?
Well I was able to reference MahApps.Metro. Seems like I was vastly over-looking it all. I'm still not sure if this is the right way to do it, however. But it works.
I referenced MahApps.Metro inside the Window.xaml itself instead of via the App.xaml, like so;
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<!-- MahApps.Metro resource dictionaries. Make sure that all file names are Case Sensitive! -->
<ResourceDictionary Source="/MahApps.Metro;component/Styles/Controls.xaml" />
<ResourceDictionary Source="/MahApps.Metro;component/Styles/Fonts.xaml" />
<!-- Accent and AppTheme setting -->
<ResourceDictionary Source="/MahApps.Metro;component/Styles/Themes/Dark.Blue.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
This also works if I create a WPF User Control which will make the overall project a bit less bloated - but the designer will not be using MahApps.Metro styles. I have yet to find a fix for this.
I has been noticed that when someone runs my application from windows 10 (I made it using windows 7) that buttons become unaligned, the only reason I can think for this happening is because of the different theme being defaulted to while being ran on the different operating systems.
How would I go about setting the default theme rather than allow it to choose depending on the operating system it is running on?
A lot of other similar questions reference a app.xaml file? but i don't seem to have this, is this auto-generated or something I would have to add myself?
The default templates of the WPF controls look different on different versions of Windows.
If you add a reference to PresentationFramework.Aero.dll and set its Copy Local property to true in Visual Studio, you can apply a Windows 7 theme your application by adding a merged ResourceDictionary into your App.xaml:
<Application ...>
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/PresentationFramework.Aero;component/themes/Aero.NormalColor.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
Besides Aero, there are some other themes (and their corresponding assemblies) available as well:
<ResourceDictionary Source="/PresentationFramework.Aero;component/themes/Aero.NormalColor.xaml"/>
<ResourceDictionary Source="/PresentationFramework.Classic;component/themes/Classic.xaml"/>
<ResourceDictionary Source="/PresentationFramework.Royale;component/themes/Royale.NormalColor.xaml"/>
<ResourceDictionary Source="/PresentationFramework.Luna.Homestead;component/themes/Luna.Homestead.xaml"/>
<ResourceDictionary Source="/PresentationFramework.Luna.Metallic;component/themes/Luna.Metallic.xaml"/>
<ResourceDictionary Source="/PresentationFramework.Zune;component/themes/Zune.NormalColor.xaml"/>
I am working with Prism modules. That means I have a lot of projects inside my solution and I would like to share my WPF styles across all of them.
Currently I am simply adding them to all my xaml files.
As Example:
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Pack://application:,,,/MyProject.Shared;component/Styles/Colors.xaml" />
</ResourceDictionary.MergedDictionaries>
<ResourceDictionary>
<UserControl.Resources>
I was wondering if there is a better solution for this problem.
Edit: The "possible duplicate" is actually what I am doing at the moment.
I want to get rid of this repetitive code snippet in each of my UserControls. Since most of my projects are UserControlLibraries / Prism Modules they don´t have a kind of App.xaml where I can define the ResourceDictionaries.
A default WPF project should have a App.xaml file. Assuming your project still has that, you can add your Resource Dictionaries there under the Application.Resources tag.
see: https://learn.microsoft.com/en-us/dotnet/framework/wpf/app-development/how-to-use-an-application-scope-resource-dictionary
I'm moving a WPF application from VS 2010 to VS 2012.
I have a main executable which contains the App.xaml and a separate class library for all the WPF stuff.
In VS2012 (SP3) the XAML designer does not show any styles which are in a MergedResourceDictionary defined in App.xaml, VS 2010 does...
For testing purposes I moved App.xaml to my class library. After that the VS 2012 designer showed everything correctly.
Since class libraries cannot contain an App.xaml this is not a solution.
Any ideas?
My App.xaml looks like the following:
<Application x:Class="MyApplication.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Startup="AppStartup">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/OtherAssemblyName;component/Resources/Resource1.xaml" />
<ResourceDictionary Source="pack://application:,,,/OtherAssemblyName;component/Resources/Resource2.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
Know this is an old question, but answering it for anyone who may face something similar in the future.
The safest way to accomplish this is to create a new ResourceDictionary file, and add the MergedResourceDictionaries in it.
Then reference that ResourceDictionary in your user control/pages/windows - all of them, since the
<UserControl.Resources>
<ResourceDictionary Source="GlobalResources.xaml" />
<UserControl.Resources>
Please let me know the difference between App.xaml and Generic.xaml, I'm confused between these two!
App.xaml is a XAML part of the Application class - the single centralized place where you define application-wide logic and resources. While Generic.xaml, being located in the Themes directory of your project, is a dictionary where you define default styles for all your custom controls. This dictionary is used when there is no windows theme-specific dictionary in the Themes folder. For example, you might have the following structure of the Themes directory:
MyProject
- Themes
- Generic.xaml // Default styles if current theme is non of the themes below
- Classic.xaml // Styles for “Classic” Windows 9x/2000 look on Windows XP.
- Luna.NormalColor.xaml // Styles for default blue theme on Windows XP.
- Luna.Homestead.xaml // Styles for olive theme on Windows XP.
- Luna.Metallic.xaml // Styles for silver theme on Windows XP.
- Royale.NormalColor.xaml // Styles for default theme on Windows XP Media Center Edition.
- Aero.NormalColor.xaml // Styles for default theme on Windows Vista
If you want you custom control to look the same on any windows theme, you need to create only Generic.xaml.
So, basically you should use Generic.xaml only to define styles for your custom control and App.xaml for everything else (e.g. your brushes, color, etc. or your own styles for standard controls).
See also the answer to this question: What is so special about Generic.xaml?
The App.xaml is used for application wide resources and is always used.
Generic.xaml is used for the templates and styles for Custom Controls and will be used when you do not specify an other style or template at control level.
App.xaml is the container for your application-level resources.
Generic.xaml is a resource file for all of your controls that are not based on a custom or default theme.
App.xaml is used for application wide resources and can therefore contain references to other XAML resources.
<Application
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" x:Class="App">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Themes/ValidationStyles.xaml"/>
<ResourceDictionary Source="Themes/ControlStyles.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
This allows you to isolate your styles in a given XAML file for manageability and will then make use of the file within the application since it is being merged into the application at runtime.
generic.xaml is used as the default the container for the default style of a custom control. The framework will look in the Themes directory for generic.xaml when resolving a style for a given type.