I use the Expression Dark Theme in my WPF application.
Also I have to use Extended WPF Toolkit Controls.
How I can apply this theme to them?
XAML:
<Application x:Uid="Application_1" x:Class="Mega.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainWindow.xaml"
SessionEnding="App_SessionEnding" >
<Application.Resources>
<ResourceDictionary x:Uid="ResourceDictionary_1" >
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary x:Uid="ResourceDictionary_3" Source="/Themes/ExpressionDark.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
You should create your own styles for each custom control from extended toolkit, because standard themes support controls from .NET Framework like button textBox etc, look into the xaml code of theme and create your style in the same way.
Related
I want to force the Aero style on my forms. I created a "WPF Class Library" and added a form and controls to this form. As the library will be called by 3rd party C# applications running on different OS, I want to force to always apply the Aero style.
But as it is a WPF class library I have no App.xaml file where I could put my Resource Dictionary.
I placed it in a dedicated custom Styles.xaml therefore and in my form I reference it like
<Window.Resources>
<ResourceDictionary Source="Styles.xaml">
</ResourceDictionary>
</Window.Resources>
where Styles.xaml looks like
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:MyLib">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/PresentationFramework.Aero;V4.0.0.0;component/themes/Aero.NormalColor.xaml"></ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
and is set to "Build action: Embedded resource" and is stored in the main project folder. I also added a reference to PresentationFramework.Aero in my project.
When I call my library form from the C# application, I get an error saying
Set property 'System.Windows.ResourceDictionary.Source' threw an exception.' Line number 'x' and line position 'y'
What did I do wrong?
This should work for you.
<ResourceDictionary Source="pack://application:,,,/PresentationFramework.Aero;component/themes/Aero.NormalColor.xaml" />
Refere this MSDN article for more details.
UPDATE
Include ResourceDictionary in PCL
Create a ResourceDictionary
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/PresentationFramework.Aero;component/themes/Aero.NormalColor.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
<!-- store here your styles -->
</ResourceDictionary>
You can use it from Your PCL in WPF App
<Window x:Class="Test.Window"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window"
Height="300"
Width="300">
<Window.Resources>
<ResourceDictionary Source="pack://application:,,,/Your.Base.AssemblyName;component/YourResDictionaryFolder/Dictionary1.xaml" />
</Window.Resources>
<Grid>
</Grid>
</Window>
Your.Base.AssemblyName = Dll name
YourResDictionaryFolder = Folder where you created your ResourceDictionary
Dictionary1.xaml = File name which you created above
First of all, great thanks to MahApps. What a cool project!
I have an existing application written in WPF that I have applied the MahApps library to. I used this tutorial:
http://mahapps.com/guides/quick-start.html
However the effect on the Property Grid (Xceed) is minimal.
The combo boxes in my other windows look like this:
The property grid combo boxes still look like this (ugly!):
However clicking on a combo box shows the right MahApps style for the items. It is only the Combo Box itself (closed) that is not flat.
My knowledge on WPF is basic. Where would I start to try and fix this? Do I need to manually override the combo box template in the Property Grid?
in MainWindow.xaml use Controls:MetroWindow
<Controls:MetroWindow x:Name="MainApp" x:Class="AppWin.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
MinHeight="700"
MinWidth="1024"
>
in MainWindow.xaml.cs inheritance MetroWindow
namespace AppWin
{
public partial class MainWindow : MetroWindow
{
...
add App.xaml following settings
<Application x:Class="AppWin.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:AppWin"
StartupUri="MainWindow.xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<!-- MahApps.Metro resource dictionaries. Make sure that all file names are Case Sensitive! -->
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colors.xaml" />
/*--change template color for example green.xaml--*/
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/red.xaml" />
/*--change template style for example BaseDark.xaml--*/
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
Perhaps your other combobox looks ugly because the MahApps resources is not found?
Place the mahapp resources you are using in a resource dictionary in the App.xaml file so it will be accessible for all windows. (and not place them in a resource dictionary in only one window, ie. mainwindow.xaml)
App.xaml:
<Application... >
<Application.Resources>
<ResourceDictionary>
<!-- My other resources -->
<!-- ... -->
<!-- MahApps resources -->
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colors.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.AnimatedSingleRowTabControl.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseDark.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
The property grid overrides the styles of MahApps. You have to create a own PropertyEditor for your properties. The PropertyEditor overrides the styles of the property grid.
I know thats a lot of work, but its the only way to get the MahApps look.
There are lots of articles online about how to embed custom fonts, create font styles and apply them to controls. But how can one override the global application font such that each control uses that font instead of setting the FontFamily property manually for each control. In my case, I do not wish to use a custom font as the global font but a system font such as Tahoma or Calibri.
In winrt default Fontfamily for all controls ContentPresenter is Segoe Ui and its key is ContentControlThemeFontFamily.
-*You can change or override fontfamily of button,comboboxitem,listboxitem etc from resourcedictionary because they have template property(contenpresenter or itempresenter)
1) Go to StandardStyles.xaml
2) Add <FontFamily x:Key="ContentControlThemeFontFamily">Tahoma</FontFamily>in default and Highcontrast resourcedictionary of ThemeDictionaries like below.
<ResourceDictionary.ThemeDictionaries>
<ResourceDictionary x:Key="Default">
<x:String x:Key="BackButtonGlyph"></x:String>
<x:String x:Key="BackButtonSnappedGlyph"></x:String>
<FontFamily x:Key="ContentControlThemeFontFamily">Tahoma</FontFamily>
</ResourceDictionary>
<ResourceDictionary x:Key="HighContrast">
<FontFamily x:Key="ContentControlThemeFontFamily">Tahoma</FontFamily>
<x:String x:Key="BackButtonGlyph"></x:String>
<x:String x:Key="BackButtonSnappedGlyph"></x:String>
</ResourceDictionary>
</ResourceDictionary.ThemeDictionaries>
But Textblock is not having template property so you can change its property like below
1. First Method
<TextBlock FontFamily="{StaticResource ContentControlThemeFontFamily }" >dfdsfsdf</TextBlock>
2. second method
<Page
x:Class="App3.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App3"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" FontFamily="{StaticResource ContentControlThemeFontFamily}">
<Grid>
<TextBlock>Hello World</TextBlock>
</Grid>
I am using Caliburn.Micro and Telerik's controls. I'm new to these so I'm assuming I am making a stupid mistake.
I have the below, VERY simple View. It's just a User Control with a GridView in it. How ever it doesn't show the GridView. Additionally I have a View that is a User Control that just shows a DataForm that also doesn't show.
I get the User control but it's blank. If I throw other controls on there they show, like a RadWatermarkTextBox or a simple TextBlock.
What am I missing? I don't get any exceptions or warnings.
<UserControl x:Name="ModifyAuthUserControl" x:Class="Green.Views.ModifyAuthView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
xmlns:cal="http://www.caliburnproject.org"
MinWidth="500" Width="600" MinHeight="550" Height="600">
<Grid Background="White">
<telerik:RadGridView x:Name="ExistingAuths"/> <!--This doesn't show-->
<telerik:RadWatermarkTextBox Text="HELLO!" /> <!--This DOES-->
</Grid>
The issue was that I had not included ALL necessary references in my App.xaml. Those two controls have multiple dependencies and I only had some of them included. Once I included the bottom two Dictionary entrees everything worked great.
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary>
<local:AppBootstrapper x:Key="bootstrapper" />
</ResourceDictionary>
<ResourceDictionary Source="/Telerik.Windows.Themes.Windows8;component/Themes/System.Windows.xaml"/>
<ResourceDictionary Source="/Telerik.Windows.Themes.Windows8;component/Themes/Telerik.Windows.Controls.xaml"/>
<ResourceDictionary Source="/Telerik.Windows.Themes.Windows8;component/Themes/Telerik.Windows.Controls.Input.xaml"/>
<ResourceDictionary Source="/Telerik.Windows.Themes.Windows8;component/Themes/Telerik.Windows.Controls.Navigation.xaml"/>
<ResourceDictionary Source="/Telerik.Windows.Themes.Windows8;component/Themes/Telerik.Windows.Controls.Docking.xaml"/>
<ResourceDictionary Source="/Telerik.Windows.Themes.Windows8;component/Themes/Telerik.Windows.Controls.Data.xaml"/>
<ResourceDictionary Source="/Telerik.Windows.Themes.Windows8;component/Themes/Telerik.Windows.Controls.GridView.xaml"/>
</ResourceDictionary.MergedDictionaries>
Note that your RadGridView and your RadWatermarkTextBox do not have associated grid rows or columns, and will appear one on top of the other.
I have a local resource in XAML and I want it to be used by other parts of the code. How can I make it "global" (i.e. an application-wide resource)? Here is my local resource:
<ResourceDictionary >
<local:BoolToLightConvertor x:Key="LightConverter" / >
</ResourceDictionary>
How can I put this in the App.xaml?
Application Resources
In addition to defining resources at the level of the element or Window, you can define
resources that are accessible by all objects in a particular application. You can create an application
resource by opening the App.xaml file (for C# projects) or the Application.xaml file
(for Visual Basic projects) and adding the resource to the Application.Resources collection, as
shown here:
<Application x:Class="WpfApplication.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="Window1.xaml">
<Application.Resources>
<SolidColorBrush x:Key="appBrush" Color="LightConverter" />
</Application.Resources>
</Application>
Create a file (e.g. SharedResources.xaml) as follows:
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Your.Namespace.Here;assembly=Your.Assembly.Here">
< local:BoolToLightConvertor x:Key="LightConverter" / >
</ResourceDictionary>
In your App.xaml add the following lines:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="SharedResources.xaml" />
</ResourceDictionary.MergedDictionaries>
<Style TargetType="{x:Type Rectangle}" />
</ResourceDictionary>
</Application.Resources>
You can now use this converter from within the XAML
(The <Style TargetType="{x:Type Rectangle}"/> is a workaround to stop a WPF bug ignoring your resource dictionary and was recommended by another question here on SO. The link unfortunately eludes me now though)