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

Add Custom mode to ColorZone #1611

Merged
merged 8 commits into from
Jan 31, 2020
25 changes: 18 additions & 7 deletions MainDemo.Wpf/ColorZones.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
<StackPanel Margin="16">
<TextBlock Style="{StaticResource MaterialDesignHeadline5TextBlock}">Colour Zones</TextBlock>
<TextBlock TextWrapping="Wrap" MaxWidth="800" Margin="0 16 0 0" Style="{StaticResource MaterialDesignSubtitle1TextBlock}">The ColorZone control allows you to easily define striking blocks of colour to give your application extra clarity and style, whilst still remaining within the bounds of your Material Design palette.</TextBlock>
<TextBlock Margin="0 16 0 0" FontSize="10">Invert the basic paper/body colours.</TextBlock>
</StackPanel>

<TextBlock Margin="0 16 0 0" Style="{StaticResource MaterialDesignSubtitle1TextBlock}">Invert the basic paper/body colours.</TextBlock>
<smtx:XamlDisplay Key="color_zones_inverted">
<materialDesign:ColorZone Mode="Inverted" Padding="16">
<DockPanel>
Expand All @@ -31,8 +32,8 @@
</DockPanel>
</materialDesign:ColorZone>
</smtx:XamlDisplay>
<TextBlock Margin="0 16 0 0" TextWrapping="Wrap" Style="{StaticResource MaterialDesignSubtitle1TextBlock}">Use primary light back and fore colours.</TextBlock>

<TextBlock Margin="0 16 0 0" Style="{StaticResource MaterialDesignSubtitle1TextBlock}">Use primary light back and fore colours.</TextBlock>
<smtx:XamlDisplay Key="color_zones_primary_light">
<materialDesign:ColorZone Mode="PrimaryLight" Padding="16">
<StackPanel Orientation="Horizontal">
Expand All @@ -41,7 +42,7 @@
</StackPanel>
</materialDesign:ColorZone>
</smtx:XamlDisplay>

<TextBlock Margin="0 16 0 0" Style="{StaticResource MaterialDesignSubtitle1TextBlock}">Use primary mid colours, and nest colour zones!</TextBlock>
<smtx:XamlDisplay Key="color_zones_primary_mid">
<materialDesign:ColorZone Mode="PrimaryMid" Padding="16">
Expand Down Expand Up @@ -78,7 +79,7 @@
</DockPanel>
</materialDesign:ColorZone>
</smtx:XamlDisplay>

<TextBlock Margin="0 16 0 0" Style="{StaticResource MaterialDesignSubtitle1TextBlock}">Add in a corner radius and shadow.</TextBlock>
<smtx:XamlDisplay Key="color_zones_primary_dark">
<materialDesign:ColorZone Mode="PrimaryDark" Padding="16" CornerRadius="3" materialDesign:ShadowAssist.ShadowDepth="Depth3" Margin="2">
Expand All @@ -88,7 +89,7 @@
</StackPanel>
</materialDesign:ColorZone>
</smtx:XamlDisplay>

<TextBlock Margin="0 16 0 0" Style="{StaticResource MaterialDesignSubtitle1TextBlock}">Use accent back and fore colours.</TextBlock>
<smtx:XamlDisplay Key="color_zones_accent">
<materialDesign:ColorZone Mode="Accent" Padding="16">
Expand All @@ -98,7 +99,17 @@
</StackPanel>
</materialDesign:ColorZone>
</smtx:XamlDisplay>


<TextBlock Margin="0 16 0 0" Style="{StaticResource MaterialDesignSubtitle1TextBlock}">Use custom back and fore colours.</TextBlock>
<smtx:XamlDisplay Key="color_zones_custom">
<materialDesign:ColorZone Mode="Custom" Background="Black" Foreground="White" Padding="16">
<StackPanel Orientation="Horizontal">
<ToggleButton Style="{DynamicResource MaterialDesignHamburgerToggleButton}" />
<TextBlock VerticalAlignment="Center" Margin="16 0 0 0">Material Design In XAML Toolkit</TextBlock>
</StackPanel>
</materialDesign:ColorZone>
</smtx:XamlDisplay>

</StackPanel>
</ScrollViewer>
</UserControl>
Expand Down
6 changes: 6 additions & 0 deletions MainDemo.Wpf/GroupBoxes.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@
<Image Source="Resources/Contact.png" VerticalAlignment="Center" HorizontalAlignment="Center" />
</GroupBox>
</smtx:XamlDisplay>

<smtx:XamlDisplay Key="groupbox_6" Grid.Column="2" Grid.Row="1">
<GroupBox Header="Custom Header" Style="{DynamicResource MaterialDesignGroupBox}" Margin="16" materialDesign:ColorZoneAssist.Mode="Custom" materialDesign:ColorZoneAssist.Background="Black" materialDesign:ColorZoneAssist.Foreground="White">
<TextBlock>My Content</TextBlock>
</GroupBox>
</smtx:XamlDisplay>
</Grid>
</UserControl>

Expand Down
14 changes: 8 additions & 6 deletions MaterialDesignThemes.Wpf/ColorZone.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace MaterialDesignThemes.Wpf
{
Expand All @@ -12,11 +13,12 @@ public enum ColorZoneMode
PrimaryDark,
Accent,
Light,
Dark
Dark,
Custom
}

/// <summary>
/// User a colour zone to easily switch the background and foreground colours, whilst still remaining within the selected Material Design palette.
/// User a colour zone to easily switch the background and foreground colours, from selected Material Design palette or custom ones.
/// </summary>
public class ColorZone : ContentControl
{
Expand All @@ -26,20 +28,20 @@ static ColorZone()
}

public static readonly DependencyProperty ModeProperty = DependencyProperty.Register(
nameof(Mode), typeof (ColorZoneMode), typeof (ColorZone), new PropertyMetadata(default(ColorZoneMode)));
nameof(Mode), typeof(ColorZoneMode), typeof(ColorZone), new PropertyMetadata(default(ColorZoneMode)));

public ColorZoneMode Mode
{
get { return (ColorZoneMode) GetValue(ModeProperty); }
get { return (ColorZoneMode)GetValue(ModeProperty); }
set { SetValue(ModeProperty, value); }
}

public static readonly DependencyProperty CornerRadiusProperty = DependencyProperty.Register(
nameof(CornerRadius), typeof (CornerRadius), typeof (ColorZone), new PropertyMetadata(default(CornerRadius)));
nameof(CornerRadius), typeof(CornerRadius), typeof(ColorZone), new PropertyMetadata(default(CornerRadius)));

public CornerRadius CornerRadius
{
get { return (CornerRadius) GetValue(CornerRadiusProperty); }
get { return (CornerRadius)GetValue(CornerRadiusProperty); }
set { SetValue(CornerRadiusProperty, value); }
}
}
Expand Down
27 changes: 27 additions & 0 deletions MaterialDesignThemes.Wpf/ColorZoneAssist.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Windows;
using System.Windows.Media;

namespace MaterialDesignThemes.Wpf
{
Expand All @@ -16,5 +17,31 @@ public static ColorZoneMode GetMode(DependencyObject element)
{
return (ColorZoneMode)element.GetValue(ModeProperty);
}

public static readonly DependencyProperty BackgroundProperty = DependencyProperty.RegisterAttached(
"Background", typeof(Brush), typeof(ColorZoneAssist), new FrameworkPropertyMetadata(default(Brush)));

public static void SetBackground(DependencyObject element, Brush value)
{
element.SetValue(BackgroundProperty, value);
}

public static Brush GetBackground(DependencyObject element)
{
return (Brush)element.GetValue(BackgroundProperty);
}

public static readonly DependencyProperty ForegroundProperty = DependencyProperty.RegisterAttached(
"Foreground", typeof(Brush), typeof(ColorZoneAssist), new FrameworkPropertyMetadata(default(Brush)));

public static void SetForeground(DependencyObject element, Brush value)
{
element.SetValue(ForegroundProperty, value);
}

public static Brush GetForeground(DependencyObject element)
{
return (Brush)element.GetValue(ForegroundProperty);
}
}
}
4 changes: 4 additions & 0 deletions MaterialDesignThemes.Wpf/Themes/Generic.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,10 @@
<Setter Property="Background" Value="{DynamicResource MaterialDesignDarkBackground}" />
<Setter Property="Foreground" Value="{DynamicResource MaterialDesignDarkForeground}" />
</Trigger>
<Trigger Property="Mode" Value="Custom">
<Setter Property="Background" Value="{Binding RelativeSource={RelativeSource Self}, Path=(local:ColorZoneAssist.Background)}" />
<Setter Property="Foreground" Value="{Binding RelativeSource={RelativeSource Self}, Path=(local:ColorZoneAssist.Foreground)}" />
</Trigger>
</Style.Triggers>
</Style>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@
<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}}"
wpf:ShadowAssist.ShadowEdges="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(wpf:ShadowAssist.ShadowEdges)}"
Mode="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(wpf:ColorZoneAssist.Mode)}"
Mode="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(wpf:ColorZoneAssist.Mode)}"
wpf:ColorZoneAssist.Background="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(wpf:ColorZoneAssist.Background)}"
wpf:ColorZoneAssist.Foreground="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(wpf:ColorZoneAssist.Foreground)}"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
<ContentPresenter ContentSource="Header" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
ContentStringFormat="{TemplateBinding HeaderStringFormat}"
Expand Down