Skip to content

Commit e3cfc89

Browse files
authored
Cleaning up color zone code (#2059)
Added UI tests for triggers
1 parent a7d4ed2 commit e3cfc89

File tree

3 files changed

+65
-17
lines changed

3 files changed

+65
-17
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using System.Threading.Tasks;
5+
using System.Windows.Media;
6+
using MaterialDesignThemes.Wpf;
7+
using XamlTest;
8+
using Xunit;
9+
using Xunit.Abstractions;
10+
11+
namespace MaterialDesignThemes.UITests.WPF.ColorZone
12+
{
13+
public class ColorZoneTests : TestBase
14+
{
15+
public ColorZoneTests(ITestOutputHelper output)
16+
: base(output)
17+
{
18+
19+
}
20+
21+
[Theory]
22+
[InlineData(ColorZoneMode.Standard, "MaterialDesignPaper", "MaterialDesignBody")]
23+
[InlineData(ColorZoneMode.Inverted, "MaterialDesignBody", "MaterialDesignPaper")]
24+
[InlineData(ColorZoneMode.PrimaryLight, "PrimaryHueLightBrush", "PrimaryHueLightForegroundBrush")]
25+
[InlineData(ColorZoneMode.PrimaryMid, "PrimaryHueMidBrush", "PrimaryHueMidForegroundBrush")]
26+
[InlineData(ColorZoneMode.PrimaryDark, "PrimaryHueDarkBrush", "PrimaryHueDarkForegroundBrush")]
27+
[InlineData(ColorZoneMode.Accent, "SecondaryHueMidBrush", "SecondaryHueMidForegroundBrush")]
28+
[InlineData(ColorZoneMode.Light, "MaterialDesignLightBackground", "MaterialDesignLightForeground")]
29+
[InlineData(ColorZoneMode.Dark, "MaterialDesignDarkBackground", "MaterialDesignDarkForeground")]
30+
public async Task Mode_SetsThemeColors(ColorZoneMode mode, string backgroundBrush, string foregroundBrush)
31+
{
32+
await using var recorder = new TestRecorder(App);
33+
34+
IVisualElement colorZone = await LoadXaml(@$"
35+
<materialDesign:ColorZone Mode=""{mode}""/>
36+
");
37+
Color background = await GetThemeColor(backgroundBrush);
38+
Color foreground = await GetThemeColor(foregroundBrush);
39+
40+
Assert.Equal(background, await colorZone.GetBackgroundColor());
41+
Assert.Equal(foreground, await colorZone.GetForegroundColor());
42+
43+
recorder.Success();
44+
}
45+
}
46+
}

MaterialDesignThemes.Wpf/ColorZone.cs

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,8 @@
11
using System.Windows;
22
using System.Windows.Controls;
3-
using System.Windows.Media;
43

54
namespace MaterialDesignThemes.Wpf
65
{
7-
public enum ColorZoneMode
8-
{
9-
Standard,
10-
Inverted,
11-
PrimaryLight,
12-
PrimaryMid,
13-
PrimaryDark,
14-
Accent,
15-
Light,
16-
Dark,
17-
Custom
18-
}
196

207
/// <summary>
218
/// User a colour zone to easily switch the background and foreground colours, from selected Material Design palette or custom ones.
@@ -32,17 +19,17 @@ static ColorZone()
3219

3320
public ColorZoneMode Mode
3421
{
35-
get { return (ColorZoneMode)GetValue(ModeProperty); }
36-
set { SetValue(ModeProperty, value); }
22+
get => (ColorZoneMode)GetValue(ModeProperty);
23+
set => SetValue(ModeProperty, value);
3724
}
3825

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

4229
public CornerRadius CornerRadius
4330
{
44-
get { return (CornerRadius)GetValue(CornerRadiusProperty); }
45-
set { SetValue(CornerRadiusProperty, value); }
31+
get => (CornerRadius)GetValue(CornerRadiusProperty);
32+
set => SetValue(CornerRadiusProperty, value);
4633
}
4734
}
4835
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
namespace MaterialDesignThemes.Wpf
2+
{
3+
public enum ColorZoneMode
4+
{
5+
Standard,
6+
Inverted,
7+
PrimaryLight,
8+
PrimaryMid,
9+
PrimaryDark,
10+
Accent,
11+
Light,
12+
Dark,
13+
Custom
14+
}
15+
}

0 commit comments

Comments
 (0)