Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 46 additions & 1 deletion MainDemo.Wpf/GroupBoxes.xaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<UserControl x:Class="MaterialDesignDemo.GroupBoxes"
<UserControl x:Class="MaterialDesignDemo.GroupBoxes"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
Expand All @@ -14,6 +14,10 @@
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.GroupBox.xaml" />
</ResourceDictionary.MergedDictionaries>

<Style TargetType="smtx:XamlDisplay" BasedOn="{StaticResource {x:Type smtx:XamlDisplay}}">
<Setter Property="MaxWidth" Value="350" />
</Style>
</ResourceDictionary>
</UserControl.Resources>

Expand All @@ -28,6 +32,7 @@
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<smtx:XamlDisplay Grid.Row="0"
Grid.Column="0"
Expand Down Expand Up @@ -174,6 +179,46 @@
Source="Resources/Contact.png" />
</GroupBox>
</smtx:XamlDisplay>

<smtx:XamlDisplay Grid.Row="3"
Grid.Column="0"
UniqueKey="groupbox_9">
<GroupBox Margin="16"
Header="Elevation"
Background="White"
materialDesign:ElevationAssist.Elevation="Dp6"
Style="{StaticResource MaterialDesignGroupBox}">
<Grid Height="50">
<TextBlock Text="GroupBox (with border) and elevation" VerticalAlignment="Center" />
</Grid>
</GroupBox>
</smtx:XamlDisplay>
<smtx:XamlDisplay Grid.Row="3"
Grid.Column="1"
UniqueKey="groupbox_10">
<GroupBox Margin="16"
Header="Elevation (no border)"
Background="White"
materialDesign:ElevationAssist.Elevation="Dp6"
BorderThickness="0"
Style="{StaticResource MaterialDesignGroupBox}">
<Grid Height="50">
<TextBlock Text="GroupBox (without border) and elevation" VerticalAlignment="Center" />
</Grid>
</GroupBox>
</smtx:XamlDisplay>
<smtx:XamlDisplay Grid.Row="3"
Grid.Column="2"
UniqueKey="groupbox_11">
<GroupBox Margin="16"
Header="Elevation on Card"
materialDesign:ElevationAssist.Elevation="Dp6"
Style="{StaticResource MaterialDesignCardGroupBox}">
<Grid Height="50">
<TextBlock Text="GroupBox (using Card style) and elevation" VerticalAlignment="Center" />
</Grid>
</GroupBox>
</smtx:XamlDisplay>
</Grid>
</UserControl>

Expand Down
14 changes: 14 additions & 0 deletions MaterialDesignThemes.Wpf/Converters/IsTransparentBrushConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.Globalization;
using System.Windows.Data;
using System.Windows.Media;

namespace MaterialDesignThemes.Wpf.Converters;

public sealed class IsTransparentBrushConverter : IValueConverter
{
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
=> value is null || Equals(value, Brushes.Transparent);

public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
=> throw new NotImplementedException();
}
29 changes: 19 additions & 10 deletions MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.GroupBox.xaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:converters="clr-namespace:MaterialDesignThemes.Wpf.Converters"
xmlns:wpf="clr-namespace:MaterialDesignThemes.Wpf">

<converters:IsTransparentBrushConverter x:Key="IsTransparentBrushConverter" />

<Style x:Key="MaterialDesignHeaderedContentControl" TargetType="{x:Type HeaderedContentControl}">
<Setter Property="Template">
<Setter.Value>
Expand All @@ -28,18 +30,17 @@
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type GroupBox}">
<Grid>
<Border Background="{TemplateBinding Background}"
<Grid x:Name="OuterGrid">
<Border x:Name="Border"
Background="{TemplateBinding Background}"
BorderBrush="{Binding Path=Background, ElementName=PART_ColorZone}"
BorderThickness="{TemplateBinding BorderThickness}" />
<DockPanel Background="{TemplateBinding Background}">
<DockPanel Margin="{TemplateBinding BorderThickness}">
<wpf:ColorZone x:Name="PART_ColorZone"
Padding="{TemplateBinding Padding}"
wpf:ColorZoneAssist.Background="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(wpf:ColorZoneAssist.Background)}"
wpf:ColorZoneAssist.Foreground="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(wpf:ColorZoneAssist.Foreground)}"
wpf:ShadowAssist.ShadowEdges="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(wpf:ShadowAssist.ShadowEdges)}"
DockPanel.Dock="Top"
Effect="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(wpf:ElevationAssist.Elevation), Converter={x:Static converters:ShadowConverter.Instance}}"
Mode="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(wpf:ColorZoneAssist.Mode)}"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
UseLayoutRounding="True">
Expand All @@ -57,6 +58,14 @@
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
</DockPanel>
</Grid>
<ControlTemplate.Triggers>
<DataTrigger Binding="{Binding ElementName=Border, Path=Background, Converter={StaticResource IsTransparentBrushConverter}}" Value="True">
<Setter TargetName="PART_ColorZone" Property="Effect" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(wpf:ElevationAssist.Elevation), Converter={x:Static converters:ShadowConverter.Instance}}" />
</DataTrigger>
<DataTrigger Binding="{Binding ElementName=Border, Path=Background, Converter={StaticResource IsTransparentBrushConverter}}" Value="False">
<Setter TargetName="OuterGrid" Property="Effect" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(wpf:ElevationAssist.Elevation), Converter={x:Static converters:ShadowConverter.Instance}}" />
</DataTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
Expand All @@ -73,14 +82,14 @@
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type GroupBox}">
<wpf:Card VerticalAlignment="Stretch">
<wpf:Card VerticalAlignment="Stretch"
wpf:ElevationAssist.Elevation="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(wpf:ElevationAssist.Elevation)}">
<DockPanel Background="{TemplateBinding Background}">
<wpf:ColorZone x:Name="PART_ColorZone"
Padding="{TemplateBinding Padding}"
wpf:ColorZoneAssist.Background="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(wpf:ColorZoneAssist.Background)}"
wpf:ColorZoneAssist.Foreground="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(wpf:ColorZoneAssist.Foreground)}"
DockPanel.Dock="Top"
Effect="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(wpf:ElevationAssist.Elevation), Converter={x:Static converters:ShadowConverter.Instance}}"
Mode="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(wpf:ColorZoneAssist.Mode)}">
<ContentPresenter ContentSource="Header"
ContentStringFormat="{TemplateBinding HeaderStringFormat}"
Expand All @@ -100,6 +109,6 @@
</Setter.Value>
</Setter>
<Setter Property="wpf:ColorZoneAssist.Mode" Value="PrimaryMid" />
<Setter Property="wpf:ElevationAssist.Elevation" Value="Dp0" />
<Setter Property="wpf:ElevationAssist.Elevation" Value="Dp1" />
</Style>
</ResourceDictionary>
</ResourceDictionary>