Default Windows theme for MessageBox with Extended WPF Toolkit - c#

I'm using custom MessageBox in my application and I need to apply my app style to it. So I use WPF Toolkit to create my MessageBox and I'm applying a MessageBoxStyle to my MessageBox :
C#:
Result = Xceed.Wpf.Toolkit.MessageBox.Show(
message,
title,
messageBoxButtons,
messageBoxImage,
(Style)resourceDictionary["MessageBoxStyle"]
);
XAML:
<Style x:Key="MessageBoxStyle" TargetType="{x:Type xctk:MessageBox}">
<!-- My Setters -->
</Style>
The problem is that it displays the basic Windows Vista window theme. I'd like my MessageBox to get the actual Windows theme of the machine (mine is Windows Server 2008 R2 E, but it might change if the application is run on another computer).
Is there a way to set this Windows theme "by default"?

WPF comes with the standard Windows themes on all Windows versions. You can have Aero theme with following steps:
Source: http://mrpmorris.blogspot.com/2008/05/using-vista-aero-theme-in-xp-wpf-apps.html
Add PresentationFramework.Aero to your application's references list as a requires
Edit your App.xaml
<Application.Resources>
<ResourceDictionary>
<!-- Put your stuff here instead -->
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/PresentationFramework.Aero;component/themes/Aero.NormalColor.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
Other options are :
<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"/>

Related

Why can't I see fonts in the Visual Studio WPF Designer?

I've been trying to use a TTF font in a WPF UserControl Library. Say I define a resource dictionary containing all of my fonts like this:
FontStyles.xaml
<ResourceDictionary ...>
<FontFamily x:Key="Ubuntu">Fonts/#Ubuntu</FontFamily>
</ResourceDictionary>
And then try to reference them in a master style dictionary, like this:
Styles.xaml
...
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="FontStyles.xaml"/>
...
</ResourceDictionary.MergedDictionaries>
<Style TargetType="TextBlock" x:Key="UbuntuExampleText">
<Setter Property="FontFamily" Value="{StaticResources Ubuntu}">
</Style>
If I then create a TextBlock with that Key, it loads the font correctly when I run my application, however, when I am previewing my UserControl in the Designer, it uses the default font. Is there a way to fix this? I haven't had this issue with images for some reason, just fonts.
I've even tried to keep my Font URIs simple to rule out a formatting issue.

Window style not visible in designer

I created a Window style (WPF) and added it as a dll to my project
this style shows corretly when i run the program but doesn't show up in the designer.
I googled already but none of the solutions there are working
Test 1:
// Window //
Style="{DynamicResource HVE_Window}"
// Window.Resources //
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/GlobalHive.Styles;component/HiveWindow.xaml"/>
</ResourceDictionary.MergedDictionaries>
Result:
Error: 'Window' TargetType doesn not match type of element 'WindowInstance'
-> But it runs and display correctly there
Test 2:
// Window //
Style="{DynamicResource MyWindow}"
// Window.Resources //
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/GlobalHive.Styles;component/HiveWindow.xaml"/>
</ResourceDictionary.MergedDictionaries>
<Style x:Key="MyWindow" TargetType="{x:Type Window}" BasedOn="{StaticResource HVE_Window}" />
Result:
No Error:
Still doesn't display in the designer, still shows up if i run the program
Test 3:
Both versions but added to application resources
How it should look:
How it looks inside the designer:
You can sometimes find that resources from a control library are not loaded at design time, despite whatever you put in app.xaml to try and load the things.
MS created a mechanism for Blend which you can use in visual studio since it's the blend designer.
This uses a "special" resource dictionary called DesignTimeResources.xaml
This will only be used at design time.
Add one to the Properties of your problem exe project.
With exactly that name.
Put all your merges into that.
eg this is one of mine from my MapEditor project that uses numerous resources from UILib. UILib is a control library with all sorts of UI stuff in it.
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:MapEditor">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/UILib;component/Resources/Geometries.xaml"/>
<ResourceDictionary Source="pack://application:,,,/UILib;component/Resources/ControlTemplates.xaml"/>
<ResourceDictionary Source="pack://application:,,,/UILib;component/Resources/FontResources.xaml"/>
<ResourceDictionary Source="pack://application:,,,/UILib;component/Resources/UILibResources.xaml"/>
<ResourceDictionary Source="/Views/Drawing/Terrain/Resources/CityResources.xaml"/>
<ResourceDictionary Source="/Resources/MapEditorResources.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
Unload your csproj ( right click in solution explorer), edit it and find the node for that resource dictionary.
Change it to:
<Page Include="Properties\DesignTimeResources.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
<ContainsDesignTimeResources>true</ContainsDesignTimeResources>
</Page>
Reload the project, close and re-open visual studio.
Your styles should now apply.

Is it possible to override one part of a control template in a Telerik WPF theme?

I am using the Telerik Windows 8 theme in my WPF application.  However, I do not like the way the checkbox checked state is indicated using a colored square rather than an actual checkmark as in the Windows 7 theme.  It was very simple to copy the checkbox template and modify it to use the checkbox checkmark from the Windows 7 theme checkbox template.
However, I am having trouble finding a way to add the style that contains this modified template to my Application.Resources in such a way as to apply it to all checkboxes in my application.  For some reason, the template in the Telerik Windows 8 theme continues to be the one that is applied.
I have tried a few different approaches, yet nothing seems to work.  My latest approach is to add the following style to my Application.Resources resource dictionary:
<Style BasedOn="{StaticResource {telerik:ThemeResourceKey ThemeType=telerik:Windows8Theme, ElementType=CheckBox}}" TargetType="CheckBox" >
    <Setter Property="Template">
    ....
    </Setter>
</Style>
Does anyone know the answer to this question? Is what I am trying to do possible?
Thanks,
Craig
Make sure you are ferencing the DLLs from the NoXaml folder of your Telerik install
Don't add any reference to any of the Theme DLLs
In your Telerik WPF install location, go into Themes.Implicit > WPF40 > Windows8 > Themes
Put the .xaml files from there into your solution
Reference them in your App.xaml resource dictionary:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Themes/Office2016/System.Windows.xaml" />
<ResourceDictionary Source="Themes/Office2016/Telerik.Windows.Controls.xaml" />
<ResourceDictionary Source="Themes/Office2016/Telerik.Windows.Controls.GridView.xaml" />
etc...
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
Now you can go into the System.Windows.xaml file, and find the style for the checkbox and edit the style to change the square to a tick
(I think it's the Rectangle called CheckVisual in the Checkbox Template which you need to change)

wpf modern-ui How can I choose a theme in code behind?

In codeplex's mui, the app.xaml goes like this
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/FirstFloor.ModernUI;component/Assets/ModernUI.xaml" />
<ResourceDictionary Source="/FirstFloor.ModernUI;component/Assets/modernui.light.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
but how can I choose the FirstFloor.ModernUI;component/Assets/modernui.light.xaml" in replace of FirstFloor.ModernUI;component/Assets/modernui.light.xaml" in code behind every time I run the program?
The ModernUI source code comes with a sample application that shows you how to do exactly what you ask.
The library has an AppearanceManager class. Set the current instance ThemeSource property:
AppearanceManager.Current.ThemeSource = AppearanceManager.LightThemeSource;

WPF not applying default styles defined in MergedDictionaries?

In a WPF application I defined default control styles in separate resource dictionaries (e.g. "ButtonStyle.xaml"), and added them as merged dictionaries to a resource dictionary named "ResDictionary.xaml".
If I refer this "ResDictionary.xaml" as merged dictionary in my App.xaml, the default styles are not applied. However, if I refer the "ButtonStyle.xaml", it works correctly.
If I recompile the same code in .NET 3.5 or 3.0, it recognizes and applies the default styles referred in "App.xaml" through "ResDictionary.xaml", but not in .NET 4.0.
At runtime if I check the Application.Current.Resources dictionary, the default styles are there, but they are not applied, only if I specify the Style property explicitly in the Button control.
Are there any solutions to refer a resource dictionary (containig default styles) this way in .NET 4.0?
App.xaml:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Styles/ResDictionary.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
ResDictionary.xaml:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Default/ButtonStyle.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
ButtonStyle.xaml:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style TargetType="Button">
<Setter Property="Background" Value="Yellow"/>
</Style>
</ResourceDictionary>
The best solution is to add a dummy default style in the resource dictionary where you merge all resources together.
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Style/Button.xaml"/>
</ResourceDictionary.MergedDictionaries>
<Style TargetType="Control" BasedOn="{StaticResource {x:Type Control}}" />
This could be caused by a known bug when there is a single style in application.resources within app.xaml when not using a startupuri.
The fix is to add an additional style like this...
...
<Style x:Key="unused" />
</Application.Resources>
for more details check out this link.... http://bengribaudo.com/blog/2010/08/19/106/bug-single-application-resources-entry-ignored
There is a sort-of fix for this, but I’ve only been able to make it work at the window level (not the application level).
In order to include a WPF 4.0 resource from a separate project, the resource must be added as a resource in the window’s code behind. The statement belongs in the window’s constructor, prior to the InitializeComponent method call:
public ControlsWindow()
{
this.Resources = Application.LoadComponent(new Uri("[WPF 4.0 ResourceProjectName];Component/[Directory and File Name within project]", UriKind.Relative)) as ResourceDictionary;
InitializeComponent();
}
Note: Replace the '[WPF 4.0 ResourceProjectName]' text with your resource's project name. Also, the '[Directory and File Name within project]' needs to be replaced with the relative location of the resource file (like 'Themes/StandardTheme.xaml')
I go into more details about this issue here.

Categories

Resources