Regarding this question and Marc's answer, I find this solution perfect, but I have trouble organizing my solution to make it functional.
How can I create a styling project that contains only XAML and reference to sub XAML, and how can I use it elsewhere in my solution? What is the visual studio project used by Marc in his answer to create the styling project?
Thank you,
B
You could create a WPF User Control Library in Visual Studio and add ResourceDictionary items where you define your XAML resources to it.
You then add a reference to this WPF User Control Library from your WPF Application project (Project->Add Reference in Visual Studio) and merge the resource dictionaries that are defined in the library in the App.xaml of your application:
<Application x:Class="WpfApplication1.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApplication4"
StartupUri="MainWindow.xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/WpfUserControlLibrary1;component/Dictionary1.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
Replace "WpfUserControlLibrary1" with the name of the WPF User Control Library and "Dictionary1" with the name of the ResourceDictionary that you added to this project.
Related
I've got a main project that is producing my executable. In the App.xaml I am defining some base styles.
Now I want to use this styles in other projects respectively in other libraries (dlls).
I read all the questions about this problems here in stackoverflow, but it doesn't work for me.
Could it be, that I get this problems, because I want to use the styles in the libraries referenced by the main project?
Thanks, Alex
You should move these styles to a separate Resource Dictionary which could be used by multiple projects/applications.
Create the resource dictionary and add it to your project and then reference it in your App.xaml:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="\shared\MyResources.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
Create a new WPF User Control Library, add a ResourceDictionary to this project and move your styles from App.xaml to this ResourceDictionary. Then you add a reference (Project->Add Reference in Visual Studio) to this new project from your WPF application and any other application in which you want to use these styles and merge the ResourceDictionary into the App.xaml:
<Application x:Class="WpfApplication1.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainWindow.xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/WpfControlLibrary1;component/ResourceDictionary1.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application>
Obviously you need to change "WpfControlLibrary1" and "ResourceDictionary1" to the actual names of the new project and ResourceDictionary respectively.
This way you have moved the common styles to a stand-alone assembly that you could use in many different applications.
Hello I'm trying to apply a theme to Fluent Ribbon but unfortunately it doesn't work. But what interesting in the visual studio designer everything works. Here is the code with I try to do it, and one more question. How to disable full screen mode in the main window?
<Application x:Class="WLDA.Server.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/Fluent;Component/Themes/Windows8/Generic.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
Test App
This might be caused by the Fluent Ribbon styles being automatically added by Orchestra for you (and they default to Office 2013).
One solution could be to remove the existing dictionary from Application.Current.Resources.MergedDictionaries and add the Windows 8 instead.
You could use the Orchestra repository (with examples) to test if this works.
I keep my app's resources in a separate DLL and reference them in my main EXE using something like this in App.xaml:-
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MyThemesAssembly;component/Themes/Generic.xaml"/>
</ResourceDictionary.MergedDictionaries>
When I edit a window that's in the main EXE project, the VS2010 designer doesn't recognise any resources from the other assembly, so I don't see any styling applied (not really an issue as I always work in the XAML view). However Resharper doesn't recognise these external resource names either, resulting in lots of squiggles under resource names when I'm editing XAML.
I've found that I can fix both the VS designer and Resharper by including the above XAML in each window and user control, but is this going to have an adverse effect on memory and/or performance? Will each window get a separate copy of the resources?
We had a problem in our application with the use of ResourceDictionaries referenced in each UserControl / View. I advise against that. We managed to reduce our application's memory footprint by like 300 mb by the use of SharedResourceDictionaries. I looks like you will end up with the ResourceDictionary being instantiated once for every single UserControl in your application. Don't do that just to fix VS designer.
Try using VS2012.
I have a test project which I was using which I was doing resource dictionary merging from an external assembly and in my app.xaml I have this:
<Application x:Class="WpfPackDictionaries.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainWindow.xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/WPFCommonLibrary;component/Vectors/Vectors.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
Then in my mainwindow.xaml I have this where the path pulls in a style ModifiablePathStyle:
<Window xmlns:Control="clr-namespace:WPF.Common.Control;assembly=WPFCommonLibrary" x:Class="WpfPackDictionaries.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Path Style="{StaticResource ModifiablePathStyle}" Fill="Red"/>
<Control:Jabberwocky />
</Grid>
</Window>
Intellisense/Resharper (V7.1 10/31 (Early Access Build)) recognizes the style and I have no squigglies:
Hence have you tried to work in VS2012?
VS2012 is able to 'see' resources since VS XAML designer loads and executes your code in design-time, so VS can inspect what resources will be available at runtime. ReSharper never uses design-time code execution (since this requires your code always be in compilable state) so XAML support became a bit more complex task.
ReSharper 8.0 implemented support for BAML decompilation and do extracts the list of XAML files and resolves XAML resources from referenced binary assemblies.
we are using Infragistics WPF controls (e.g. xamDataGrid, xamDockManager etc), and we will be using the Infragistics Office 2007 Blue theme which these controls support.
We also want to style the rest of the application (i.e. standard WPF controls) using the same Office 2007 Blue style.
What's the best approach? Are there Office 2007 themes/skins that we can download or purchase? Can we use anything from the Infragistics download?
I know this is an old question, but maybe little update can be helpful for anyone that stumbles upon this. It is working in current version of Infragistics. Resource in App.xaml in enough. Sources point to folder in solution that contains files from Infragistics themes (usually something like C:\Program Files (x86)\Infragistics\2015.1\WPF\Themes).
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Theme/Styles.Shared.xaml" />
<ResourceDictionary Source="/Theme/Styles.WPF.xaml" />
<ResourceDictionary Source="/Theme/Theme.Colors.xaml" />
<ResourceDictionary Source="/Theme/IG.MSControls.Core.Implicit.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
IIRC for winforms infragistics allow you to use the app stylist to be able to theme the standard controls.
Just had a quick look on the forums and it doesn't look like it can be done for WPF.
How to apply themes to non-Infragistics controls
I'm trying to learn more about WPF. I ran through an online tutorial that created a button and then created a template to be applied to additional buttons. The problem is this template is in the Window.xaml and I can only access the template from within that application. How do I make the template more globablly available? I'm thinking of some way to reference the xaml like you can reference an assembly from a different project or solution.
You can use "resource dictionaries" which you reference in your App.xaml like this (Expression Blend does it automatically):
<Application.Resources>
<!-- Resources scoped at the Application level should be defined here. -->
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="ResourceDictionary1.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
How to reference a resource from another assembly, use pack URI syntax. This link covers it as well.