MahApps Dialog overriding Button style? - wpf

I'm using the MahApps metro toolkit, and have the following inside my Apps.xaml file:
<Application.Resources>
<ResourceDictionary>
...
<Style TargetType="{x:Type Button}" />
...
</ResourceDictionary>
</Application.Resources>
Which nicely overrides the MahApps metro style for Button back to 'default'.
However, I've written a custom dialog (called DialogEditGroup - which derives from CustomDialog), but weirdly the <Button /> style has reverted back to using some form of styling from the MahApps metro toolkit.
The only way I've been able to reset it again, is by adding the following lower down in my Apps.xaml ResourceDictionary:
<Style TargetType="{x:Type controls:DialogEditGroup}">
<Style.Resources>
<Style TargetType="{x:Type Button}" />
</Style.Resources>
</Style>
I really don't want to have to add this in for every custom dialog I write, and I'm sure the above 'fix' isn't the correct way of solving the problem. Can anyone suggest a proper way of addressing this issue?
`
(Top of image is 'mahapps', bottom is 'default / generic')

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.

Designer ignores BasedOn Style during design time, works during runtime

There seems to be a bug or limitation on the WPF designer's ability to infer the style to display during design time.
I am skinning my app and have a base window style in my app.xaml:
<Application.Resources>
<Style x:Key="WindowStyleBase" TargetType="ContentControl">
<Setter Property="Background" Value="Red" />
</Style>
<Style x:Key="WindowStyle" TargetType="{x:Type Window}" BasedOn="{StaticResource WindowStyleBase}">
<!-- <Setter Property="Background" Value="Red" /> -->
</Style>
</Application.Resources>
And I skin my window using the static resource WindowStyle :
<Window x:Class="XamlBasedOnBreaker.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" Style="{StaticResource WindowStyle}">
<Grid>
</Grid>
</Window>
Now when I run the application, I see the red background, but during design time in visual studio 2013 and expression blend the background is white (default). The designer does not apply the proper style.
How do I fix this? I have multiple user controls etc on which I want the WindowStyle that's why I subclass the style and use BasedOn. If I move the red color into WindowStyle instead of WindowStyleBase it works, but this would result in too much copy paste code, even if I would use resources for the brushes as I have quite a number of user controls.
Further more I am skinning a dark theme and having a white background during design time is more than inconvenient.

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>

What is the most economical way to implement your own window border and title bar?

I am pretty new to WPF and am sitting here with my book trying to figure out the best approach to this application.
The title bar is not part of the client area so I am making my own title bar.
Which way would it be easiest to make this into some sort of resource to apply to all new windows I create?
<Application.Resources>
<Style x:Key="WindowTheme">
<Setter Property="Window.WindowStyle" Value="None"/>
</Style>
<!--Would I create a user control here for the title bar/border and title bar buttons? Or would it be a style?-->
</Application.Resources>
In WPF, there are two ways to use styles: Named styles and typed styles. A named style has an x:Key="..." attribute. A typed style doesn't have a name, but a TargetType="..." attribute (Rem: Named styles can and very often do have a TargetType as well, so named styles and unnamed styles would be more precise). Typed styles automatically get applied to all controls in the scope, which are of type TargetType (not a derived type).
<Style TargetType="{x:Type Window}">
<Setter Property="Background" Value="Blue" />
</Style>
To create your own window, you can set it's template property to a UserControl in the style:
<Style TargetType="{x:Type Window}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
The professional way to implement the control template is to implement it 'from scratch', this means not using a UserControl which derives from Window. To do this, you define the visual tree of the Window, and use the WPF feature TemplateParts to define what part of your control template is responsible for what functionality of the window.
Here is a tutorial which describes pretty exactly what you want to do:
CodeProject tutorial

Silverlight: Change style for state

My App.xaml looks like this:
<Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="mySilverlightApp.App"
>
<Application.Resources>
<Style x:Name="ComboBoxStyle" TargetType="ComboBox">
<Setter Property="FontFamily" Value="Calibri.ttf#Calibri"></Setter>
</Style>
</Application.Resources>
As you can see, I'm trying to apply custom styling with <Setter> tags to ComboBoxes in my app. But I want to apply styling for different states of the ComboBox (MouseOver, etc).
How can I do this?
To accomplish this, you'll have to create a control template in your implicit style. Something like the following:
<Style x:Name="ComboBoxStyle" TargetType="ComboBox">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ComboBox">
....
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
You can refer to this link for the default styles/controltemplates for the combobox: http://msdn.microsoft.com/en-us/library/dd334408(v=vs.95).aspx
A great way to get started re-templating controls is using Blend. You can right click a control you have dragged onto the artboard and use the "Edit Template -> Edit a Copy" command. This will create a default controltemplate for you (the same one shown in the link I provided).
From there you can edit the mouse-over state in Blend by using the States tab.
There's alot going on here, but this should get you started on the right path.

Resources