Skip to content

Commit 205e1f8

Browse files
committed
Added a fallback color parameter.
1 parent 0ba8fd1 commit 205e1f8

1 file changed

Lines changed: 28 additions & 6 deletions

File tree

ColorSetKit/Color.cs

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,35 @@ namespace ColorSetKit
3434
[MarkupExtensionReturnType( typeof( SolidColorBrush ) )]
3535
public partial class Color: MarkupExtension
3636
{
37-
public Color( string name ): this( name, false )
37+
public Color( string name ): this( name, false, null )
3838
{}
3939

40-
public Color( string name, bool variant )
40+
public Color( string name, SolidColorBrush fallback ): this( name, false, fallback )
41+
{}
42+
43+
public Color( string name, bool variant ): this( name, variant, null )
44+
{}
45+
46+
public Color( string name, bool variant, SolidColorBrush fallback )
4147
{
42-
this.Name = name;
43-
this.Variant = variant;
48+
this.Name = name;
49+
this.Variant = variant;
50+
this.Fallback = fallback;
4451
}
4552

4653
public override object ProvideValue( IServiceProvider provider )
4754
{
48-
ColorPair color = ColorSet.Shared.ColorNamed( this.Name );
55+
if( ColorSet.Shared.ColorNamed( this.Name ) is ColorPair pair )
56+
{
57+
if( this.Variant && pair.Variant != null )
58+
{
59+
return pair.Variant;
60+
}
61+
62+
return pair.Color ?? this.Fallback;
63+
}
4964

50-
return this.Variant && color?.Variant is SolidColorBrush variant ? variant : color?.Color;
65+
return this.Fallback;
5166
}
5267

5368
[ConstructorArgument( "name" )]
@@ -59,6 +74,13 @@ public string Name
5974

6075
[ConstructorArgument( "variant" )]
6176
public bool Variant
77+
{
78+
get;
79+
set;
80+
}
81+
82+
[ConstructorArgument( "fallback" )]
83+
public SolidColorBrush Fallback
6284
{
6385
get;
6486
set;

0 commit comments

Comments
 (0)