Skip to content

Commit f5c1ad6

Browse files
committed
beginnings of colour zones [skip ci]
1 parent cffbd20 commit f5c1ad6

File tree

4 files changed

+95
-1
lines changed

4 files changed

+95
-1
lines changed

MaterialDesignColors.WpfExample/MainWindow.xaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
44
xmlns:wpfExample="clr-namespace:MaterialDesignColors.WpfExample"
5+
xmlns:wpf="clr-namespace:MaterialDesignThemes.Wpf;assembly=MaterialDesignThemes.Wpf"
56
Title="Material Design in XAML" Height="600" Width="800"
67
TextElement.Foreground="{DynamicResource MaterialDesignBody}"
78
TextElement.FontWeight="Medium"
@@ -85,7 +86,8 @@
8586
<Button Click="ProgressButton_OnClick" Margin="48 0 0 0">PROGRESS</Button>
8687
</StackPanel>
8788
<wpfExample:Buttons Visibility="{Binding ElementName=ButtonsRadioButton, Path=IsChecked, Converter={StaticResource BooleanToVisibilityConverter}}" />
88-
<wpfExample:TextFields Visibility="{Binding ElementName=FieldsRadioButton, Path=IsChecked, Converter={StaticResource BooleanToVisibilityConverter}}" />
89+
<wpfExample:TextFields Visibility="{Binding ElementName=FieldsRadioButton, Path=IsChecked, Converter={StaticResource BooleanToVisibilityConverter}}" />
90+
8991
</DockPanel>
9092

9193
</Window>

MaterialDesignThemes.Wpf/ColorZone.cs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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 MaterialDesignThemes.Wpf
17+
{
18+
public enum ColorZoneMode
19+
{
20+
Standard,
21+
Inverted,
22+
PrimaryLight,
23+
PrimaryMid,
24+
PrimaryDark,
25+
Accent
26+
}
27+
28+
/// <summary>
29+
/// User a colour zone to easily switch the background and foreground colours, whilst still remaining within the selected Material Design palette.
30+
/// </summary>
31+
public class ColorZone : ContentControl
32+
{
33+
static ColorZone()
34+
{
35+
DefaultStyleKeyProperty.OverrideMetadata(typeof(ColorZone), new FrameworkPropertyMetadata(typeof(ColorZone)));
36+
}
37+
38+
public static readonly DependencyProperty ModeProperty = DependencyProperty.Register(
39+
"Mode", typeof (ColorZoneMode), typeof (ColorZone), new PropertyMetadata(default(ColorZoneMode)));
40+
41+
public ColorZoneMode Mode
42+
{
43+
get { return (ColorZoneMode) GetValue(ModeProperty); }
44+
set { SetValue(ModeProperty, value); }
45+
}
46+
}
47+
}

MaterialDesignThemes.Wpf/MaterialDesignThemes.Wpf.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@
182182
<Compile Include="Clock.cs" />
183183
<Compile Include="ClockChoiceMadeEventArgs.cs" />
184184
<Compile Include="ClockItemButton.cs" />
185+
<Compile Include="ColorZone.cs" />
185186
<Compile Include="Converters\BrushToRadialGradientBrushConverter.cs" />
186187
<Compile Include="Converters\CalendarDateCoalesceConverter.cs" />
187188
<Compile Include="Converters\ClockItemIsCheckedConverter.cs" />

MaterialDesignThemes.Wpf/Themes/Generic.xaml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,4 +286,48 @@
286286
</Setter>
287287
</Style>
288288

289+
<Style TargetType="{x:Type local:ColorZone}">
290+
<Setter Property="Background" Value="{DynamicResource MaterialDesignPaper}" />
291+
<Setter Property="Foreground" Value="{DynamicResource MaterialDesignBody}" />
292+
<Setter Property="Template">
293+
<Setter.Value>
294+
<ControlTemplate TargetType="{x:Type local:ColorZone}">
295+
<Border Background="{TemplateBinding Background}"
296+
BorderBrush="{TemplateBinding BorderBrush}"
297+
BorderThickness="{TemplateBinding BorderThickness}">
298+
<ContentPresenter Content="{TemplateBinding Content}"
299+
ContentTemplate="{TemplateBinding ContentTemplate}"
300+
TextElement.Foreground="{TemplateBinding Foreground}"
301+
RecognizesAccessKey="True"
302+
Cursor="{TemplateBinding Cursor}"
303+
Margin="{TemplateBinding Padding}"
304+
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
305+
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
306+
</Border>
307+
</ControlTemplate>
308+
</Setter.Value>
309+
</Setter>
310+
<Style.Triggers>
311+
<Trigger Property="Mode" Value="Inverted">
312+
<Setter Property="Background" Value="{DynamicResource MaterialDesignBody}" />
313+
<Setter Property="Foreground" Value="{DynamicResource MaterialDesignPaper}" />
314+
</Trigger>
315+
<Trigger Property="Mode" Value="PrimaryLight">
316+
<Setter Property="Background" Value="{DynamicResource PrimaryHueLightBrush}" />
317+
<Setter Property="Foreground" Value="{DynamicResource PrimaryHueLightForegroundBrush}" />
318+
</Trigger>
319+
<Trigger Property="Mode" Value="PrimaryMid">
320+
<Setter Property="Background" Value="{DynamicResource PrimaryHueMidBrush}" />
321+
<Setter Property="Foreground" Value="{DynamicResource PrimaryHueMidForegroundBrush}" />
322+
</Trigger>
323+
<Trigger Property="Mode" Value="PrimaryLight">
324+
<Setter Property="Background" Value="{DynamicResource PrimaryHueDarkBrush}" />
325+
<Setter Property="Foreground" Value="{DynamicResource PrimaryHueDarkForegroundBrush}" />
326+
</Trigger>
327+
<Trigger Property="Mode" Value="Accent">
328+
<Setter Property="Background" Value="{DynamicResource SecondaryAccentBrush}" />
329+
<Setter Property="Foreground" Value="{DynamicResource SecondaryAccentForegroundBrush}" />
330+
</Trigger>
331+
</Style.Triggers>
332+
</Style>
289333
</ResourceDictionary>

0 commit comments

Comments
 (0)