Skip to content

Commit afd1ff4

Browse files
committed
Styles for material group box
1 parent e56afb6 commit afd1ff4

File tree

8 files changed

+201
-0
lines changed

8 files changed

+201
-0
lines changed

MainDemo.Wpf/GroupBoxes.xaml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<UserControl x:Class="MaterialDesignColors.WpfExample.GroupBoxes"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
7+
xmlns:local="clr-namespace:MaterialDesignDemo"
8+
mc:Ignorable="d"
9+
d:DesignHeight="300" d:DesignWidth="300">
10+
<UserControl.Resources>
11+
12+
<ResourceDictionary>
13+
<ResourceDictionary.MergedDictionaries>
14+
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.GroupBox.xaml" />
15+
</ResourceDictionary.MergedDictionaries>
16+
</ResourceDictionary>
17+
18+
</UserControl.Resources>
19+
<Grid>
20+
<Grid.ColumnDefinitions>
21+
<ColumnDefinition/>
22+
<ColumnDefinition/>
23+
<ColumnDefinition/>
24+
</Grid.ColumnDefinitions>
25+
<Grid.RowDefinitions>
26+
<RowDefinition/>
27+
<RowDefinition/>
28+
</Grid.RowDefinitions>
29+
30+
<GroupBox Grid.Column="0" Grid.Row="0" Header="Default Look" Margin="16">
31+
<TextBlock>My Content</TextBlock>
32+
</GroupBox>
33+
34+
<GroupBox Grid.Column="1" Grid.Row="0" Header="Shadow Header" Style="{DynamicResource MaterialDesignGroupBox}" Margin="16" materialDesign:ShadowAssist.ShadowDepth="Depth3" BorderThickness="0">
35+
<TextBlock Margin="6,6,6,6" TextWrapping="Wrap">Short loin picanha boudin pork belly. Ground round porchetta biltong, cow t-bone tri-tip strip steak chuck filet mignon jowl turducken. Landjaeger strip steak pork chop, jowl sirloin pork capicola andouille. Kevin ribeye tongue, drumstick hamburger frankfurter t-bone corned beef beef biltong cow venison. Biltong picanha bresaola pork belly, filet mignon spare ribs doner pork chop kielbasa. Swine flank drumstick pork belly pancetta spare ribs rump filet mignon.</TextBlock>
36+
</GroupBox>
37+
38+
<Border Grid.Column="2" Grid.Row="0" Background="{DynamicResource MaterialDesignBackground}">
39+
<GroupBox Header="Transparent Background" Style="{DynamicResource MaterialDesignGroupBox}" Margin="16" UseLayoutRounding="True" SnapsToDevicePixels="True">
40+
<TextBlock>My Content</TextBlock>
41+
</GroupBox>
42+
</Border>
43+
<GroupBox Grid.Column="0" Grid.Row="1" Header="Accent Header" Style="{DynamicResource MaterialDesignGroupBox}" Margin="16" materialDesign:ColorZoneAssist.Mode="Accent">
44+
<TextBlock>My Content</TextBlock>
45+
</GroupBox>
46+
47+
<GroupBox Grid.Column="1" Grid.Row="1" Header="Card Group Box" Style="{DynamicResource MaterialDesignCardGroupBox}" Margin="16">
48+
<GroupBox.HeaderTemplate>
49+
<DataTemplate>
50+
<StackPanel Orientation="Horizontal">
51+
<materialDesign:PackIcon Kind="ImageArea" Height="32" Width="32" VerticalAlignment="Center" />
52+
<TextBlock Margin="8,0,0,0" VerticalAlignment="Center" Style="{StaticResource MaterialDesignSubheadingTextBlock}" Text="{Binding}"/>
53+
</StackPanel>
54+
</DataTemplate>
55+
</GroupBox.HeaderTemplate>
56+
<Image Source="Resources/Contact.png" VerticalAlignment="Center" HorizontalAlignment="Center" />
57+
</GroupBox>
58+
</Grid>
59+
</UserControl>

MainDemo.Wpf/GroupBoxes.xaml.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using System.Windows;
7+
using System.Windows.Controls;
8+
using System.Windows.Data;
9+
using System.Windows.Documents;
10+
using System.Windows.Input;
11+
using System.Windows.Media;
12+
using System.Windows.Media.Imaging;
13+
using System.Windows.Navigation;
14+
using System.Windows.Shapes;
15+
16+
namespace MaterialDesignColors.WpfExample
17+
{
18+
/// <summary>
19+
/// Interaction logic for GroupBoxes.xaml
20+
/// </summary>
21+
public partial class GroupBoxes : UserControl
22+
{
23+
public GroupBoxes()
24+
{
25+
InitializeComponent();
26+
}
27+
}
28+
}

MainDemo.Wpf/MainWindow.xaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@
7474
<wpfExample:TextFields />
7575
</domain:DemoItem.Content>
7676
</domain:DemoItem>
77+
<domain:DemoItem Name="Group Boxes">
78+
<domain:DemoItem.Content>
79+
<wpfExample:GroupBoxes />
80+
</domain:DemoItem.Content>
81+
</domain:DemoItem>
7782
<domain:DemoItem Name="Pickers">
7883
<domain:DemoItem.Content>
7984
<wpfExample:Pickers>

MainDemo.Wpf/MaterialDesignDemo.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@
110110
<Compile Include="Grids.xaml.cs">
111111
<DependentUpon>Grids.xaml</DependentUpon>
112112
</Compile>
113+
<Compile Include="GroupBoxes.xaml.cs">
114+
<DependentUpon>GroupBoxes.xaml</DependentUpon>
115+
</Compile>
113116
<Compile Include="Home.xaml.cs">
114117
<DependentUpon>Home.xaml</DependentUpon>
115118
</Compile>
@@ -224,6 +227,10 @@
224227
<SubType>Designer</SubType>
225228
<Generator>MSBuild:Compile</Generator>
226229
</Page>
230+
<Page Include="GroupBoxes.xaml">
231+
<SubType>Designer</SubType>
232+
<Generator>MSBuild:Compile</Generator>
233+
</Page>
227234
<Page Include="Home.xaml">
228235
<SubType>Designer</SubType>
229236
<Generator>MSBuild:Compile</Generator>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using System.Windows;
7+
8+
namespace MaterialDesignThemes.Wpf
9+
{
10+
public static class ColorZoneAssist
11+
{
12+
public static readonly DependencyProperty ModeProperty = DependencyProperty.RegisterAttached(
13+
"Mode", typeof(ColorZoneMode), typeof(ColorZoneAssist), new FrameworkPropertyMetadata(default(ColorZoneMode), FrameworkPropertyMetadataOptions.Inherits));
14+
15+
public static void SetMode(DependencyObject element, ColorZoneMode value)
16+
{
17+
element.SetValue(ModeProperty, value);
18+
}
19+
20+
public static ColorZoneMode GetMode(DependencyObject element)
21+
{
22+
return (ColorZoneMode)element.GetValue(ModeProperty);
23+
}
24+
}
25+
}

MaterialDesignThemes.Wpf/MaterialDesignThemes.Wpf.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@
103103
<SubType>Designer</SubType>
104104
<Generator>MSBuild:Compile</Generator>
105105
</Page>
106+
<Page Include="Themes\MaterialDesignTheme.GroupBox.xaml">
107+
<Generator>MSBuild:Compile</Generator>
108+
<SubType>Designer</SubType>
109+
</Page>
106110
<Page Include="Themes\MaterialDesignTheme.Label.xaml">
107111
<SubType>Designer</SubType>
108112
<Generator>MSBuild:Compile</Generator>
@@ -218,6 +222,7 @@
218222
<Compile Include="ClockChoiceMadeEventArgs.cs" />
219223
<Compile Include="ClockItemButton.cs" />
220224
<Compile Include="ColorZone.cs" />
225+
<Compile Include="ColorZoneAssist.cs" />
221226
<Compile Include="ComboBoxPopup.cs" />
222227
<Compile Include="Converters\BrushRoundConverter.cs" />
223228
<Compile Include="Converters\BrushToRadialGradientBrushConverter.cs" />

MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.Defaults.xaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Expander.xaml" />
1515
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Font.xaml" />
1616
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.GridSplitter.xaml" />
17+
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.GroupBox.xaml" />
1718
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Hyperlink.xaml" />
1819
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/materialdesigntheme.Label.xaml" />
1920
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/materialdesigntheme.Listbox.xaml" />
@@ -51,6 +52,7 @@
5152
<Style TargetType="{x:Type DatePicker}" BasedOn="{StaticResource MaterialDesignDatePicker}" />
5253
<Style TargetType="{x:Type Expander}" BasedOn="{StaticResource MaterialDesignExpander}" />
5354
<Style TargetType="{x:Type GridSplitter}" BasedOn="{StaticResource MaterialDesignGridSplitter}" />
55+
<Style TargetType="{x:Type GroupBox}" BasedOn="{StaticResource MaterialDesignGroupBox}" />
5456
<Style TargetType="{x:Type Label}" BasedOn="{StaticResource MaterialDesignLabel}" />
5557
<Style TargetType="{x:Type ListBox}" BasedOn="{StaticResource MaterialDesignListBox}" />
5658
<Style TargetType="{x:Type PasswordBox}" BasedOn="{StaticResource MaterialDesignPasswordBox}" />
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
2+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3+
xmlns:converters="clr-namespace:MaterialDesignThemes.Wpf.Converters"
4+
xmlns:wpf="clr-namespace:MaterialDesignThemes.Wpf"
5+
>
6+
7+
<Style x:Key="MaterialDesignHeaderedContentControl" TargetType="{x:Type HeaderedContentControl}">
8+
<Setter Property="Template">
9+
<Setter.Value>
10+
<ControlTemplate TargetType="{x:Type HeaderedContentControl}">
11+
<StackPanel>
12+
<wpf:ColorZone>
13+
<ContentPresenter ContentSource="Header"/>
14+
</wpf:ColorZone>
15+
<ContentPresenter/>
16+
</StackPanel>
17+
</ControlTemplate>
18+
</Setter.Value>
19+
</Setter>
20+
</Style>
21+
22+
23+
<Style x:Key="MaterialDesignGroupBox" TargetType="{x:Type GroupBox}">
24+
<Setter Property="Background" Value="Transparent"/>
25+
<Setter Property="Foreground" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type FrameworkElement}}, Path=(TextElement.Foreground)}"/>
26+
<Setter Property="Padding" Value="6,6,6,6"/>
27+
<Setter Property="BorderThickness" Value="1"/>
28+
<Setter Property="SnapsToDevicePixels" Value="true"/>
29+
<Setter Property="wpf:ShadowAssist.ShadowDepth" Value="Depth0" />
30+
<Setter Property="wpf:ColorZoneAssist.Mode" Value="PrimaryMid" />
31+
<Setter Property="Template">
32+
<Setter.Value>
33+
<ControlTemplate TargetType="{x:Type GroupBox}">
34+
<Border Background="{TemplateBinding Background}" BorderBrush="{Binding Path=Background, ElementName=PART_ColorZone}" BorderThickness="{TemplateBinding BorderThickness}">
35+
<DockPanel Background="{TemplateBinding Background}">
36+
<wpf:ColorZone UseLayoutRounding="True" x:Name="PART_ColorZone" DockPanel.Dock="Top" Padding="{TemplateBinding Padding}" Effect="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(wpf:ShadowAssist.ShadowDepth), Converter={x:Static converters:ShadowConverter.Instance}}" Mode="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(wpf:ColorZoneAssist.Mode)}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
37+
<ContentPresenter ContentSource="Header" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
38+
</wpf:ColorZone>
39+
<ContentPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" Margin="{TemplateBinding Padding}"/>
40+
</DockPanel>
41+
</Border>
42+
</ControlTemplate>
43+
</Setter.Value>
44+
</Setter>
45+
</Style>
46+
47+
<Style x:Key="MaterialDesignCardGroupBox" TargetType="{x:Type GroupBox}">
48+
<Setter Property="Background" Value="Transparent"/>
49+
<Setter Property="Foreground" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type FrameworkElement}}, Path=(TextElement.Foreground)}"/>
50+
<Setter Property="Padding" Value="6,6,6,6"/>
51+
<Setter Property="BorderThickness" Value="0"/>
52+
<Setter Property="SnapsToDevicePixels" Value="true"/>
53+
<Setter Property="wpf:ShadowAssist.ShadowDepth" Value="Depth0" />
54+
<Setter Property="wpf:ColorZoneAssist.Mode" Value="PrimaryMid" />
55+
<Setter Property="Template">
56+
<Setter.Value>
57+
<ControlTemplate TargetType="{x:Type GroupBox}">
58+
<wpf:Card VerticalAlignment="Stretch">
59+
<DockPanel Background="{TemplateBinding Background}">
60+
<wpf:ColorZone x:Name="PART_ColorZone" DockPanel.Dock="Top" Padding="{TemplateBinding Padding}" Effect="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(wpf:ShadowAssist.ShadowDepth), Converter={x:Static converters:ShadowConverter.Instance}}" Mode="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(wpf:ColorZoneAssist.Mode)}">
61+
<ContentPresenter ContentSource="Header" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
62+
</wpf:ColorZone>
63+
<ContentPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" Margin="{TemplateBinding Padding}"/>
64+
</DockPanel>
65+
</wpf:Card>
66+
</ControlTemplate>
67+
</Setter.Value>
68+
</Setter>
69+
</Style>
70+
</ResourceDictionary>

0 commit comments

Comments
 (0)