right to left dialog in mahapps - wpf

I'm using Mahapps,metro toolkit for create a WPF application.I want to show a right to left dialog.
await this.ShowMessageAsync("This is the title", "Some message");
I am usig above code to create dialog but it is left to right.

This is how to align right in a MessageBox. You should check to see if there is a similar way to do this using MahApps.Metro:
MessageBox.Show("hi", "hey", MessageBoxButton.OK, MessageBoxImage.Information, MessageBoxResult.OK, MessageBoxOptions.RightAlign);
The parameters, in order, are:
Message
Title
Button type
Icon displayed
Button type that is returned by user click
Display options (this is the parameter you are looking for)
This creates the following dialog box:

I found the solution.just add this style to app.xaml
<Style TargetType="{x:Type Dialog:MessageDialog}"
BasedOn="{StaticResource {x:Type Dialog:BaseMetroDialog}}">
<Setter Property="FlowDirection" Value="RightToLeft" />
</Style>
Here is my app.xaml file
<Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:RandomQuestions"
xmlns:Dialogs="clr-namespace:MahApps.Metro.Controls.Dialogs;assembly=MahApps.Metro"
xmlns:controls="http://metro.mahapps.com/winfx/xaml/controls"
StartupUri="MainWindow.xaml">
<Application.Resources>
<ResourceDictionary >
<Style TargetType="{x:Type Dialogs:MessageDialog}" BasedOn="{StaticResource {x:Type Dialogs:BaseMetroDialog}}">
<Setter Property="FlowDirection" Value="RightToLeft" />
</Style>
<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" />
<!-- Accent and AppTheme setting -->
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Amber.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>

Related

How can I apply a Metro style to the Page Control in WPF?

I'm working on a project with WPF using Microsoft Visual Studio Ultimate 2013. I'm trying to use an style similar to Visual Studio Dark Theme and this article Visual Studio 2012 Metro Styles for WPF helped me to achieve this. I am setting up a style for Menu, Button, ComboBox, DataGrid, ScrollBar, TextBox and others, but for the control Page I don't found a way to get in Metro Style.
This is my app.xaml
Application x:Class="Chem.Managment.Visual.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:,,,/Selen.Wpf.Core;component/MetroWindowResources.xaml"/>
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml"/>
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.Tooltip.xaml"/>
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.Buttons.xaml"/>
<ResourceDictionary Source="pack://application:,,,/Selen.Wpf.Core;component/Resources.xaml"/>
<ResourceDictionary Source="pack://application:,,,/Selen.Wpf.SystemStyles;component/MenuStyles.xaml"/>
<ResourceDictionary Source="pack://application:,,,/Selen.Wpf.SystemStyles;component/ButtonStyles.xaml"/>
<ResourceDictionary Source="pack://application:,,,/Selen.Wpf.SystemStyles;component/ComboBoxStyles.xaml"/>
<ResourceDictionary Source="pack://application:,,,/Selen.Wpf.SystemStyles;component/DataGridStyles.xaml"/>
<ResourceDictionary Source="pack://application:,,,/Selen.Wpf.SystemStyles;component/GroupBoxStyles.xaml"/>
<ResourceDictionary Source="pack://application:,,,/Selen.Wpf.SystemStyles;component/ScrollBarStyles.xaml"/>
<ResourceDictionary Source="pack://application:,,,/Selen.Wpf.SystemStyles;component/TextBoxStyles.xaml"/>
<ResourceDictionary Source="pack://application:,,,/Selen.Wpf.SystemStyles;component/WindowStyles.xaml"/>
<ResourceDictionary Source="ChemResDict.xaml" />
</ResourceDictionary.MergedDictionaries>
<Style TargetType="Button" BasedOn="{StaticResource StandardButton}"/>
<Style TargetType="Window" BasedOn="{StaticResource StandardWindow}"/>
<Style TargetType="Menu" BasedOn="{StaticResource StandardMenu}"/>
<Style TargetType="ScrollBar" BasedOn="{StaticResource StandardScrollBar}"/>
<Style TargetType="TextBox" BasedOn="{StaticResource StandardTextBox}"/>
<Style TargetType="DataGrid" BasedOn="{StaticResource StandardDataGrid}"/>
<Style TargetType="ComboBox" BasedOn="{StaticResource StandardComboBox}"/>
<Style TargetType="GroupBox" BasedOn="{StaticResource StandardGroupBox}"/>
</ResourceDictionary>
</Application.Resources>
</Application>
I tried to add the page control in the code above but I don't know how, maybe it is not implemented.
What am I missing here? Any suggestion please.
Thanks in advance
The style for Pages is defined in Controls.Page.xaml wich is referenced from Controls.xaml. As I check your resources you do not import none of the previously mentioned resources. According to the documentation of MahApps you have to include the following resources in order to have the full MahApps experience:
<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" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Blue.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml" />
As theme you can use BaseLight.xaml or BaseDark.xaml, as accent you find any possible color on GitHub.

MahApps Metro setting Window Border styles from App Resources

I am trying to set Window Border styles for my MahApps Metro app. I have read the articles about how to set the different Border styles and I think I get it. However, I am trying to set the Border Style for all windows in my app to be the same (all Drop Shadow) and it doesn't seem to want to work.
I have app resources that look like this:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/GSDXThemes;component/GSDXDarkYellowTheme.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
My Resource dictionary looks like this:
<!-- Merge in ResourceDictionaries defining base styles to use. This theme is based on the Metro Dark Yellow theme. -->
<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/Accents/Yellow.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseDark.xaml" />
<ResourceDictionary Source="pack://application:,,,/GSDXThemes;component/GSDXControlStyles.xaml" />
</ResourceDictionary.MergedDictionaries>
The GSDXControlStyles dictionary just sets some custom style values for my app. It is in this file that I try to set the Window Borders.
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:resx="clr-namespace:GSDXThemes.Properties"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:System="clr-namespace:System;assembly=mscorlib"
xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
xmlns:GSDUserControls="clr-namespace:GSD.CommonGUI.UserControls;assembly=CommonGUI">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
</ResourceDictionary.MergedDictionaries>
<!-- Now customize the theme for our use...mostly just changing font sizes, etc...-->
<Style TargetType="{x:Type Controls:MetroWindow}" >
<Setter Property="WindowTransitionsEnabled" Value="False" />
<Setter Property="EnableDWMDropShadow" Value="True" />
</Style>
<Style TargetType="{x:Type Label}" BasedOn="{StaticResource MetroLabel}">
<Setter Property="FontSize" Value="16"/>
</Style>
<Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource MetroTextBox}">
<Setter Property="FontSize" Value="16"/>
</Style>
...
All the other style settings work fine. But the first line for setting the Window Border does nothing. All my windows show with no border.
How can I get this to work so all Windows have the Drop Shadow border?
you must give your style a key to get a working solution
<Style x:Key="CustomDefaultWindowStyle"
TargetType="{x:Type Controls:MetroWindow}"
BasedOn="{StaticResource {x:Type Controls:MetroWindow}}" >
<Setter Property="WindowTransitionsEnabled" Value="False" />
<Setter Property="EnableDWMDropShadow" Value="True" />
</Style>
now use this style on all your MetroWindows
<Controls:MetroWindow x:Class="YourWindowClass"
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"
xmlns:System="clr-namespace:System;assembly=mscorlib"
Title="Custom Window Style Demo"
Height="600"
Width="800"
WindowStartupLocation="CenterScreen"
Style="{DynamicResource CustomDefaultWindowStyle}">
...
</Controls:MetroWindow>
(don't be afraid of the'Invalid style target type:...' message, it's a VS bug)
hope that helps

MahApps style should not apply to all items

I noticed when adding the MahApps.Metro styles to my resource dictionary that these styles are being applied to all items within my application, this is not the desired effect. I only want to use the ToggleSwitch and Combobox Styles. How can this be achieved?
Thanx!
put only the following resource dictionaries in your xaml
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colours.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.Buttons.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.ComboBox.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Blue.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml" />
</ResourceDictionary.MergedDictionaries>
<Style TargetType="ToggleButton" BasedOn="{StaticResource MetroToggleButton}" />
<Style TargetType="ComboBox" BasedOn="{StaticResource MetroComboBox}" />
<Style TargetType="ComboBoxItem" BasedOn="{StaticResource MetroComboBoxItem}" />
</ResourceDictionary>
hope this helps

Mixing general WPF styles with ResourceDictionary

I came from web development and WinForms to WPF and maybe I didn't get the concept yet.
I'm able to define general styles for my Application in the app.xaml. For example I defined the style for all my ribbon controls in this file.
Then I tried Microsoft Blend and came across ResourceDictionary, which is somekind of Resource File .resx I knew from WinForms.
But as I see it's not possible to mix these two concepts. For example following xaml code will not work because ResourceDictionary have to be the only child.
<Application x:Class="Wpf.MyApplication.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ribbon="clr-namespace:Microsoft.Windows.Controls.Ribbon;assembly=RibbonControlsLibrary"
StartupUri="MyMainWindow.xaml">
<Application.Resources>
<!-- Resources scoped at the Application level should be defined here. -->
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Styles/RibbonStyle.xaml"/>
</ResourceDictionary.MergedDictionaries>
<BitmapImage x:Key="IconDokumentNeu" >Images/NewDocument_32x32.png</BitmapImage>
<SolidColorBrush x:Key="LightGrayBrushKey">WhiteSmoke</SolidColorBrush>
</ResourceDictionary>
<Style TargetType="{x:Type ribbon:RibbonWindow}">
<Setter Property="Icon" Value="../time2_32.png" />
<Setter Property="TextOptions.TextFormattingMode" Value="Display" />
</Style>
</Application.Resources>
</Application>
It seems I didn't really get the concept. Maybe you can help me, why this is not possible and how I can use general styles next to ResourceDictionary.
You already have resources defined "next to" the dictionary, one image and one brush.
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<!-- Dictionaries from file here -->
</ResourceDictionary.MergedDictionaries>
<!-- Other resources here -->
</ResourceDictionary>
</Application.Resources>
Just include the {x:type} style in the resource dictionary
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<!-- Dictionaries from file here -->
</ResourceDictionary.MergedDictionaries>
<Style TargetType="{x:Type ribbon:RibbonWindow}">
<Setter Property="Icon" Value="../time2_32.png" />
<Setter Property="TextOptions.TextFormattingMode" Value="Display" />
</Style>
</ResourceDictionary>

how do i inherit/overwrite a forced style from a windows theme?

currently i am forcing my WPF app to use the luna theme no matter what, with this XAML code
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Styles.xaml" />
<ResourceDictionary Source="NavigationCommands.xaml" />
<ResourceDictionary Source="/RibbonControlsLibrary;component/Themes/Office2007Blue.xaml"/>
<ResourceDictionary Source="/PresentationFramework.Luna, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, ProcessorArchitecture=MSIL;;component/Themes/luna.normalcolor.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
and now i want to extend the style of every textbox with this validation trigger
<Style TargetType="TextBox">
<Style.Triggers>
<Trigger Property="Validation.HasError" Value="true">
<Setter Property="Background" Value="#d3e1f3"></Setter>
<Setter Property="ToolTip"
Value="{Binding RelativeSource={RelativeSource Self},
Path=(Validation.Errors)[0].ErrorContent}"/>
</Trigger>
</Style.Triggers>
</Style>
but this trigger does not work, because i forced the luna theme. (without the forced theme every thing works as it should, but doesn't look as it should :( )
is there some way to force the luna theme and extend it's style? probably over the BasedOn property?
atm i defined a key for the style in question and added it to every textbox by hand, that works but isn't the prettiest way to go.
tia
Try
<Style x:Key="{x:Type TextBox}" TargetType="{x:Type TextBox}">
The BasedOn syntax for type styles is as follows:
<Style TargetType="TextBox" BasedOn="{StaticResource {x:Type TextBox}}">
HTH
Have you tried to set the lune resourcedictionary first and your own resourcedictionary last?
I can imagine the luna theme overrides your style.
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/PresentationFramework.Luna, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, ProcessorArchitecture=MSIL;;component/Themes/luna.normalcolor.xaml" />
<ResourceDictionary Source="/RibbonControlsLibrary;component/Themes/Office2007Blue.xaml"/>
<ResourceDictionary Source="Styles.xaml" />
<ResourceDictionary Source="NavigationCommands.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
Use the mentioned
<Style TargetType="TextBox" BasedOn="{StaticResource {x:Type TextBox}}">
but also make sure your dictionaries are included in right order - first the ones you are basing your style on
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/RibbonControlsLibrary;component/Themes/Office2007Blue.xaml"/>
<ResourceDictionary Source="/PresentationFramework.Luna, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, ProcessorArchitecture=MSIL;;component/Themes/luna.normalcolor.xaml" />
<ResourceDictionary Source="Styles.xaml" />
<ResourceDictionary Source="NavigationCommands.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>

Resources