Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expander enhancements #1988

Merged
merged 13 commits into from
Jun 21, 2015
22 changes: 22 additions & 0 deletions MahApps.Metro/Controls/Helper/ControlsHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,28 @@ namespace MahApps.Metro.Controls
/// </summary>
public static class ControlsHelper
{
public static readonly DependencyProperty PreserveTextCaseProperty = DependencyProperty.RegisterAttached("PreserveTextCase", typeof(bool), typeof(ControlsHelper), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.Inherits | FrameworkPropertyMetadataOptions.AffectsMeasure));

/// <summary>
/// Gets the value to override the text case behavior for the header content.
/// When set to <c>true</c>, the text case will be preserved and won't be changed to upper or lower case.
/// </summary>
[AttachedPropertyBrowsableForType(typeof(Expander))]
[AttachedPropertyBrowsableForType(typeof(GroupBox))]
public static bool GetPreserveTextCase(UIElement element)
{
return (bool)element.GetValue(PreserveTextCaseProperty);
}

/// <summary>
/// Sets the value to override the text case behavior for the header content.
/// When set to <c>true</c>, the text case will be preserved and won't be changed to upper or lower case.
/// </summary>
public static void SetPreserveTextCase(UIElement element, bool value)
{
element.SetValue(PreserveTextCaseProperty, value);
}

public static readonly DependencyProperty HeaderFontSizeProperty =
DependencyProperty.RegisterAttached("HeaderFontSize", typeof(double), typeof(ControlsHelper), new FrameworkPropertyMetadata(26.67, HeaderFontSizePropertyChangedCallback){ Inherits = true});

Expand Down
88 changes: 88 additions & 0 deletions MahApps.Metro/Controls/Helper/ExpanderHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
using System.Windows;
using System.Windows.Controls;

namespace MahApps.Metro.Controls
{
/// <summary>
/// A helper class that provides various attached properties for the Expander control.
/// <see cref="Expander"/>
/// </summary>
public static class ExpanderHelper
{
public static readonly DependencyProperty HeaderUpStyleProperty = DependencyProperty.RegisterAttached("HeaderUpStyle", typeof(Style), typeof(ExpanderHelper), new FrameworkPropertyMetadata((Style)null, FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.AffectsMeasure));

/// <summary>
/// Gets the toggle button style used for the ExpandDirection Up.
/// </summary>
[AttachedPropertyBrowsableForType(typeof(Expander))]
public static Style GetHeaderUpStyle(UIElement element)
{
return (Style)element.GetValue(HeaderUpStyleProperty);
}

/// <summary>
/// Sets the toggle button style used for the ExpandDirection Up.
/// </summary>
public static void SetHeaderUpStyle(UIElement element, Style value)
{
element.SetValue(HeaderUpStyleProperty, value);
}

public static readonly DependencyProperty HeaderDownStyleProperty = DependencyProperty.RegisterAttached("HeaderDownStyle", typeof(Style), typeof(ExpanderHelper), new FrameworkPropertyMetadata((Style)null, FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.AffectsMeasure));

/// <summary>
/// Gets the toggle button style used for the ExpandDirection Down.
/// </summary>
[AttachedPropertyBrowsableForType(typeof(Expander))]
public static Style GetHeaderDownStyle(UIElement element)
{
return (Style)element.GetValue(HeaderDownStyleProperty);
}

/// <summary>
/// Sets the toggle button style used for the ExpandDirection Down.
/// </summary>
public static void SetHeaderDownStyle(UIElement element, Style value)
{
element.SetValue(HeaderDownStyleProperty, value);
}

public static readonly DependencyProperty HeaderLeftStyleProperty = DependencyProperty.RegisterAttached("HeaderLeftStyle", typeof(Style), typeof(ExpanderHelper), new FrameworkPropertyMetadata((Style)null, FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.AffectsMeasure));

/// <summary>
/// Gets the toggle button style used for the ExpandDirection Left.
/// </summary>
[AttachedPropertyBrowsableForType(typeof(Expander))]
public static Style GetHeaderLeftStyle(UIElement element)
{
return (Style)element.GetValue(HeaderLeftStyleProperty);
}

/// <summary>
/// Sets the toggle button style used for the ExpandDirection Left.
/// </summary>
public static void SetHeaderLeftStyle(UIElement element, Style value)
{
element.SetValue(HeaderLeftStyleProperty, value);
}

public static readonly DependencyProperty HeaderRightStyleProperty = DependencyProperty.RegisterAttached("HeaderRightStyle", typeof(Style), typeof(ExpanderHelper), new FrameworkPropertyMetadata((Style)null, FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.AffectsMeasure));

/// <summary>
/// Gets the toggle button style used for the ExpandDirection Right.
/// </summary>
[AttachedPropertyBrowsableForType(typeof(Expander))]
public static Style GetHeaderRightStyle(UIElement element)
{
return (Style)element.GetValue(HeaderRightStyleProperty);
}

/// <summary>
/// Sets the toggle button style used for the ExpandDirection Right.
/// </summary>
public static void SetHeaderRightStyle(UIElement element, Style value)
{
element.SetValue(HeaderRightStyleProperty, value);
}
}
}
72 changes: 72 additions & 0 deletions MahApps.Metro/Converters/ThicknessBindingConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;

namespace MahApps.Metro.Converters
{
/// <summary>
/// Converts a Thickness to a new Thickness. It's possible to ignore a side With the IgnoreThicknessSide property.
/// </summary>
public class ThicknessBindingConverter : IValueConverter
{
public IgnoreThicknessSideType IgnoreThicknessSide { get; set; }

public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is Thickness)
{
// yes, we can override it with the parameter value
if (parameter is IgnoreThicknessSideType)
{
this.IgnoreThicknessSide = (IgnoreThicknessSideType)parameter;
}
var orgThickness = (Thickness)value;
switch (this.IgnoreThicknessSide)
{
case IgnoreThicknessSideType.Left:
return new Thickness(0, orgThickness.Top, orgThickness.Right, orgThickness.Bottom);
case IgnoreThicknessSideType.Top:
return new Thickness(orgThickness.Left, 0, orgThickness.Right, orgThickness.Bottom);
case IgnoreThicknessSideType.Right:
return new Thickness(orgThickness.Left, orgThickness.Top, 0, orgThickness.Bottom);
case IgnoreThicknessSideType.Bottom:
return new Thickness(orgThickness.Left, orgThickness.Top, orgThickness.Right, 0);
default:
return orgThickness;
}
}
return default(Thickness);
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
// for now no back converting
return DependencyProperty.UnsetValue;
}
}

public enum IgnoreThicknessSideType
{
/// <summary>
/// Use all sides.
/// </summary>
None,
/// <summary>
/// Ignore the left side.
/// </summary>
Left,
/// <summary>
/// Ignore the top side.
/// </summary>
Top,
/// <summary>
/// Ignore the right side.
/// </summary>
Right,
/// <summary>
/// Ignore the bottom side.
/// </summary>
Bottom
}
}
2 changes: 2 additions & 0 deletions MahApps.Metro/MahApps.Metro.NET45.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@
<DependentUpon>GlowWindow.xaml</DependentUpon>
</Compile>
<Compile Include="Controls\Helper\DataGridCellHelper.cs" />
<Compile Include="Controls\Helper\ExpanderHelper.cs" />
<Compile Include="Controls\Helper\GroupBoxHelper.cs" />
<Compile Include="Controls\MetroAnimatedSingleRowTabControl.cs" />
<Compile Include="Controls\MetroAnimatedTabControl.cs" />
Expand Down Expand Up @@ -202,6 +203,7 @@
<Compile Include="Controls\WindowCommands.cs" />
<Compile Include="Converters\ResizeModeMinMaxButtonVisibilityConverter.cs" />
<Compile Include="Converters\StringToVisibilityConverter.cs" />
<Compile Include="Converters\ThicknessBindingConverter.cs" />
<Compile Include="Converters\ThicknessToDoubleConverter.cs" />
<Compile Include="Converters\TreeViewMarginConverter.cs" />
<Compile Include="Microsoft.Windows.Shell\Standard\ComGuids.cs" />
Expand Down
2 changes: 2 additions & 0 deletions MahApps.Metro/MahApps.Metro.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@
<Compile Include="Controls\Helper\ComboBoxHelper.cs" />
<Compile Include="Controls\Helper\ControlsHelper.cs" />
<Compile Include="Controls\Helper\DataGridCellHelper.cs" />
<Compile Include="Controls\Helper\ExpanderHelper.cs" />
<Compile Include="Controls\Helper\GroupBoxHelper.cs" />
<Compile Include="Controls\Helper\PasswordBoxHelper.cs" />
<Compile Include="Controls\Helper\ScrollBarHelper.cs" />
Expand Down Expand Up @@ -150,6 +151,7 @@
</Compile>
<Compile Include="Controls\WindowCommandsOverlayBehavior.cs" />
<Compile Include="Converters\BackgroundToForegroundConverter.cs" />
<Compile Include="Converters\ThicknessBindingConverter.cs" />
<Compile Include="Converters\IsNullConverter.cs" />
<Compile Include="Converters\FontSizeOffsetConverter.cs" />
<Compile Include="Converters\MetroTabItemCloseButtonWidthConverter.cs" />
Expand Down
59 changes: 41 additions & 18 deletions MahApps.Metro/Styles/Clean/CleanGroupBox.xaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
<ResourceDictionary 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"
xmlns:Converters="clr-namespace:MahApps.Metro.Converters">
<Style TargetType="GroupBox"
xmlns:Controls="clr-namespace:MahApps.Metro.Controls">

<Style TargetType="GroupBox"
x:Key="CleanGroupBoxStyleKey">
<Setter Property="BorderThickness" Value="0.3" />
<Setter Property="BorderBrush"
Value="{DynamicResource GrayBrush7}" />
<Setter Property="BorderThickness"
Value="0.3" />
<Setter Property="Controls:ControlsHelper.HeaderFontSize"
Value="16" />
<Setter Property="Controls:GroupBoxHelper.HeaderForeground"
Value="{DynamicResource TextBrush}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="GroupBox">
Expand All @@ -17,40 +22,58 @@
</Grid.RowDefinitions>

<ContentPresenter Margin="{TemplateBinding Padding}"
Content="{TemplateBinding Header}"
ContentTemplate="{TemplateBinding HeaderTemplate}"
ContentTemplateSelector="{TemplateBinding HeaderTemplateSelector}"
ContentStringFormat="{TemplateBinding HeaderStringFormat}"
TextElement.Foreground="{TemplateBinding Controls:GroupBoxHelper.HeaderForeground}"
TextElement.FontSize="{TemplateBinding Controls:ControlsHelper.HeaderFontSize}"
TextElement.FontStretch="{TemplateBinding Controls:ControlsHelper.HeaderFontStretch}"
TextElement.FontWeight="{TemplateBinding Controls:ControlsHelper.HeaderFontWeight}"
ContentSource="Header"
ContentTemplate="{TemplateBinding HeaderTemplate}"
RecognizesAccessKey="True"
Grid.Row="0">
</ContentPresenter>
Grid.Row="0" />

<Grid VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Grid.Row="1">
<Grid VerticalAlignment="Stretch"
HorizontalAlignment="Stretch"
Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.Resources>
<Style x:Key="InternalBorderStyle" TargetType="Border">
<Setter Property="VerticalAlignment" Value="Stretch" />
<Setter Property="BorderBrush" Value="{DynamicResource GrayBrush7}" />
<Setter Property="Background" Value="{DynamicResource GrayBrush7}" />
<Setter Property="Panel.ZIndex" Value="1" />
<Setter Property="Width" Value="Auto" />
<Style x:Key="InternalBorderStyle"
TargetType="Border">
<Setter Property="VerticalAlignment"
Value="Stretch" />
<Setter Property="Panel.ZIndex"
Value="1" />
<Setter Property="Width"
Value="Auto" />
</Style>
</Grid.Resources>

<Border Grid.Column="0" Style="{StaticResource InternalBorderStyle}" BorderThickness="{TemplateBinding BorderThickness}" />
<Border Grid.Column="0"
Style="{StaticResource InternalBorderStyle}"
BorderBrush="{TemplateBinding BorderBrush}"
Background="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}" />

<ContentPresenter Grid.Column="1" />
<ContentPresenter Grid.Column="1"
Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}"
Cursor="{TemplateBinding Cursor}" />

<Border Grid.Column="2" Style="{StaticResource InternalBorderStyle}" BorderThickness="{TemplateBinding BorderThickness}" />
<Border Grid.Column="2"
Style="{StaticResource InternalBorderStyle}"
BorderBrush="{TemplateBinding BorderBrush}"
Background="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}" />
</Grid>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

</ResourceDictionary>
Loading