Skip to content

Commit 28006f2

Browse files
committed
Added a markup extension.
1 parent f8b12a2 commit 28006f2

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

ColorSetKit/Color.cs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*******************************************************************************
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2018 Jean-David Gadina - www.imazing.com
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
******************************************************************************/
24+
25+
using System;
26+
using System.Collections.Generic;
27+
using System.Linq;
28+
using System.Text;
29+
using System.Windows.Markup;
30+
using System.Windows.Media;
31+
32+
namespace ColorSetKit
33+
{
34+
[MarkupExtensionReturnType( typeof( SolidColorBrush ) )]
35+
public partial class Color: MarkupExtension
36+
{
37+
public Color( string name )
38+
{
39+
this.Name = name;
40+
}
41+
42+
public override object ProvideValue( IServiceProvider provider )
43+
{
44+
return ColorSet.Shared.ColorNamed( this.Name );
45+
}
46+
47+
[ConstructorArgument( "name" )]
48+
public string Name
49+
{
50+
get;
51+
set;
52+
}
53+
}
54+
}

ColorSetKit/ColorSetKit.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,15 @@
3535
<Reference Include="PresentationCore" />
3636
<Reference Include="System" />
3737
<Reference Include="System.Core" />
38+
<Reference Include="System.Xaml" />
3839
<Reference Include="System.Xml.Linq" />
3940
<Reference Include="System.Data.DataSetExtensions" />
4041
<Reference Include="Microsoft.CSharp" />
4142
<Reference Include="System.Data" />
4243
<Reference Include="System.Xml" />
4344
</ItemGroup>
4445
<ItemGroup>
46+
<Compile Include="Color.cs" />
4547
<Compile Include="ColorPair.cs" />
4648
<Compile Include="ColorSet.cs" />
4749
<Compile Include="ColorSetStream.cs" />

0 commit comments

Comments
 (0)