Change Background for all MetroWindow (MahApp) - wpf

I've just started using MahApps with WPF. I would like to change background color of all MetroWindow. This post indicates how to do it for one instance of a MetroWindow, but is there a way to override the default background color for this control type?
I would expect to be able to change it by customizing a Mahapps theme. I created a custom theme (copied from BaseDark.xaml), changed all SolidColorBrush values, applied the theme in the OnStartup event using "ThemeManager.ChangeAppStyle" but the MetroWindow background didn't change.
This code (put in the App.xaml) doesn't work either:
<Style BasedOn="{StaticResource {x:Type Controls:MetroWindow}}" TargetType="{x:Type Controls:MetroWindow}">
<Setter Property="Background" Value="LightGray" />
</Style>
In addition to MetroWindow, I would also like to override the background color of the System.Windows.Controls.UserControl type.

I found the Color in the Mahapps theme that change the MetroWindow background color:
<Color x:Key="WhiteColor">#FF373F44</Color>

Related

How to change ShowMessageAsync flow direction to "Right to Left"?

Is there any way to change Mahapps messagebox window (ShowMessageAsync)'s flow direction to Right to left ?
You can set the FlowDirection for the whole MetroWindow and all childrens.
FlowDirection="RightToLeft"
If you only want to set this to MessageDialog then you can change the style e.g. in your App.xaml like this
<Style TargetType="{x:Type Dialog:MessageDialog}"
BasedOn="{StaticResource {x:Type Dialog:BaseMetroDialog}}">
<Setter Property="FlowDirection" Value="RightToLeft" />
</Style>
So all message dialogs will get this style.
Hope this helps!
Overwriting the style should do it,
see: How to change MahApps.Metro dialog content template width?
The answer has a nice little tutorial.

Custom control not inheriting parent's styles

I'm trying to maintain a uniform look and feel across elements in my WPF application, and at the same time I want to create a modified TextBox. However, when I do this, styles that I define at the application level for TextBox aren't being applied to the class I created, even though the style created for my custom control is using the BasedOn property.
Is there something I'm missing that's causing this to behave differently than I expect?
I reproduced the issue in a brand-new WPF project in VS2010 with this setup:
C# Code:
public class CustomTextBox : TextBox
{
static CustomTextBox() {
DefaultStyleKeyProperty.OverrideMetadata(typeof(CustomTextBox), new FrameworkPropertyMetadata(typeof(CustomTextBox)));
}
}
XAML in Themes\Generic.xaml:
<Style TargetType="{x:Type local:CustomTextBox}" BasedOn="{StaticResource {x:Type TextBox}}"/>
XAML in App.xaml:
<Application.Resources>
<Style TargetType="TextBox">
<Setter Property="Background" Value="Red"/>
</Style>
</Application.Resources>
However, in the designer and when I run the app, the CustomTextBox falls back onthe default styling for the text box instead of having a red background, even though the documentation for the BasedOn property suggests that my derived class should have this styling...
There are several ways that styles in WPF can be extended or inherited. Styles can be based on other styles through this property. When you use this property, the new style will inherit the values of the original style that are not explicitly redefined in the new style.
...
Note: If you create a style with a TargetType property and base it on another style that also defines a TargetType property, the target type of the derived style must be the same as or be derived from the type of the base style.
Short Answer: Your style is based on a StaticResource
<Style TargetType="{x:Type local:CustomTextBox}" BasedOn="{StaticResource {x:Type TextBox}}"/>
When you did this, you are not changing the StaticResource
<Style TargetType="TextBox">
<Setter Property="Background" Value="Red"/>
</Style>
So CustomTextBox is not supposed to inherit the red background.

WPF MahApps.Metro AnimatedSingleRowTabControl FontSize

How do I change the font size of the tabs when using the MahApps.Metro AnimatedSingleRowTabControl.
When using a normal TabControl, my theme TabItem (based on MetroTabItem) overrides the fontsize but this does not work for the animated single row tab control. I tried setting the fontsize property on the control in the XAML and this didn't work either.
Regards
Alan
You can also define the following in the Application.Resources your App.xaml:
<system:Double x:Key="TabItemFontSize">16</system:Double>
Controls.TabControl.xaml makes use of it as follows:
<Setter Property="Controls:ControlsHelper.HeaderFontSize"
Value="{DynamicResource TabItemFontSize}" />
You can do the following, setting the header font size to whatever value you want:
<metro:MetroAnimatedSingleRowTabControl>
<metro:MetroAnimatedSingleRowTabControl.ItemContainerStyle>
<Style TargetType="{x:Type metro:MetroTabItem}" BasedOn="{StaticResource {x:Type metro:MetroTabItem}}">
<Setter Property="HeaderFontSize" Value="24"/>
</Style>
</metro:MetroAnimatedSingleRowTabControl.ItemContainerStyle>
</metro:MetroAnimatedSingleRowTabControl>

Changing glow speed in default WPF Button

The default WPF button we have in Visual Studio: when mouse hover on it, the button background will glow from grey to blue. The speed is too slow. How to speed up the glowing effect in XAML?
Is there something like below?:
<Style TargetType="{x:Type Button}" BasedOn="{StaticResource {x:Type Button}}">
<Setter Property="GlowSpeed" Value="0.01" />
</Style>
Of course, this property doesn't exist. What property is that suppose to be? Is that some sort of Animation?
This animation is embedded in the default Template of the button, you would need to change the default template which can be found on MSDN (Default WPF Themes link).

Derived classes and theme inheritance in WPF?

I'm building a WPF application, and I derived a bunch of controls from the standard WPF control types -- textblocks, buttons, etc. I tried adding a resource dictionary to app.xaml to set the theme, but my custom controls don't seem to be respecting it. (For example, standard Buttons take the Aero theme just fine, but a myButton derived from a Button is still lookless.) Is there a way I can set the theme for my derived controls to be the same as for the base controls?
EDIT: I should note that these custom controls are instantiated at runtime, so I can't manipulate their properties directly via XAML. I can change particular properties like background color by using a Setter in the application resource dictionary, but haven't found a way to set a theme using that technique.
If you have this style in a Resource Dictionary called Dictionary1.xaml
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style x:Key="MyButtonStyle"
TargetType="{x:Type Button}"
BasedOn="{StaticResource {x:Type Button}}">
<Setter Property="Width" Value="75" />
<Setter Property="Height" Value="23" />
</Style>
</ResourceDictionary>
Then you can set it on any button with this code behind
Uri resourceLocater = new Uri("/YourAssemblyName;component/Dictionary1.xaml", System.UriKind.Relative);
ResourceDictionary resourceDictionary = (ResourceDictionary)Application.LoadComponent(resourceLocater);
Style myButtonStyle = resourceDictionary["MyButtonStyle"] as Style;
Button button = new Button();
button.Style = myButtonStyle;

Resources