forked from CommunityToolkit/Lottie-Windows
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ColorPaletteEntry.cs
60 lines (50 loc) · 1.99 KB
/
ColorPaletteEntry.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable disable // Temporary while enabling nullable everywhere.
using System.ComponentModel;
using Windows.UI;
namespace LottieViewer
{
// An observable named color with the ability to change the color value.
public sealed class ColorPaletteEntry : INotifyPropertyChanged
{
Color _initialColor;
Color _color;
internal ColorPaletteEntry(Color color, string name)
{
_initialColor = color;
_color = color;
Name = name;
}
public event PropertyChangedEventHandler PropertyChanged;
/// <summary>
/// If true, changing the Color will also change the InitialColor to keep it the
/// same as Color. This is used to special case the "Background" color, which does
/// not have an initial color.
/// </summary>
public bool IsInitialColorSameAsColor { get; set; }
public Color Color
{
get => _color;
set
{
// Check whether the color is actually changing, and ignore it if it isn't.
// This check ensures we can use two-way binding without infinite recursion.
if (value != _color)
{
_color = value;
if (IsInitialColorSameAsColor)
{
_initialColor = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(this.InitialColor)));
}
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(this.Color)));
}
}
}
public Color InitialColor => _initialColor;
// A name that describes the palette entry.
public string Name { get; set; }
}
}