-
Notifications
You must be signed in to change notification settings - Fork 455
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added basic support for IconSource and its subclasses (#192)
* Ported IconSource and its sub classes from WinUI * Resolved suggestions * Added headers with copyright & license notices to avoid potential licensing issues * Removed an unnecessary duplicate class and moved code into an existing file to resolved CS0436 warning
- Loading branch information
1 parent
e8335aa
commit 7643681
Showing
6 changed files
with
390 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. See LICENSE in the project root for license information. | ||
|
||
using System; | ||
using System.Windows; | ||
using System.Windows.Media.Imaging; | ||
|
||
namespace ModernWpf.Controls | ||
{ | ||
/// <summary> | ||
/// Represents an icon source that uses a bitmap as its content. | ||
/// </summary> | ||
public class BitmapIconSource : IconSource | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="BitmapIconSource"/> class. | ||
/// </summary> | ||
public BitmapIconSource() | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Identifies the <see cref="UriSource"/> dependency property. | ||
/// </summary> | ||
public static readonly DependencyProperty UriSourceProperty = | ||
BitmapImage.UriSourceProperty.AddOwner(typeof(BitmapIconSource)); | ||
|
||
/// <summary> | ||
/// Gets or sets the Uniform Resource Identifier (URI) of the bitmap to use as the icon content. | ||
/// </summary> | ||
/// <returns> | ||
/// The <see cref="Uri"/> of the bitmap to use as the icon content. The default is <see langword="null"/>. | ||
/// </returns> | ||
public Uri UriSource | ||
{ | ||
get => (Uri)GetValue(UriSourceProperty); | ||
set => SetValue(UriSourceProperty, value); | ||
} | ||
|
||
/// <summary> | ||
/// Identifies the <see cref="ShowAsMonochrome"/> dependency property. | ||
/// </summary> | ||
public static readonly DependencyProperty ShowAsMonochromeProperty = | ||
DependencyProperty.Register( | ||
nameof(ShowAsMonochrome), | ||
typeof(bool), | ||
typeof(BitmapIconSource), | ||
new PropertyMetadata(true)); | ||
|
||
/// <summary> | ||
/// Gets or sets a value that indicates whether the bitmap is shown in a single color. | ||
/// </summary> | ||
/// <returns> | ||
/// <see langword="true"/> to show the bitmap in a single color; | ||
/// <see langword="false"/> to show the bitmap in full color. The default is <see langword="true"/>. | ||
/// </returns> | ||
public bool ShowAsMonochrome | ||
{ | ||
get => (bool)GetValue(ShowAsMonochromeProperty); | ||
set => SetValue(ShowAsMonochromeProperty, value); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. See LICENSE in the project root for license information. | ||
|
||
using System.Windows; | ||
using System.Windows.Media; | ||
|
||
namespace ModernWpf.Controls | ||
{ | ||
/// <summary> | ||
/// Represents an icon source that uses a glyph from the specified font. | ||
/// </summary> | ||
public class FontIconSource : IconSource | ||
{ | ||
const string c_fontIconSourceDefaultFontFamily = "Segoe MDL2 Assets"; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="FontIconSource"/> class. | ||
/// </summary> | ||
public FontIconSource() | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Identifies the <see cref="FontFamily"/> dependency property. | ||
/// </summary> | ||
public static readonly DependencyProperty FontFamilyProperty = | ||
DependencyProperty.Register( | ||
nameof(FontFamily), | ||
typeof(FontFamily), | ||
typeof(FontIconSource), | ||
new PropertyMetadata(new FontFamily(c_fontIconSourceDefaultFontFamily))); | ||
|
||
/// <summary> | ||
/// Gets or sets the font used to display the icon glyph. | ||
/// </summary> | ||
/// <returns> | ||
/// The font used to display the icon glyph. | ||
/// </returns> | ||
public FontFamily FontFamily | ||
{ | ||
get => (FontFamily)GetValue(FontFamilyProperty); | ||
set => SetValue(FontFamilyProperty, value); | ||
} | ||
|
||
/// <summary> | ||
/// Identifies the <see cref="FontSize"/> dependency property. | ||
/// </summary> | ||
public static readonly DependencyProperty FontSizeProperty = | ||
DependencyProperty.Register( | ||
nameof(FontSize), | ||
typeof(double), | ||
typeof(FontIconSource), | ||
new PropertyMetadata(20.0)); | ||
|
||
/// <summary> | ||
/// Gets or sets the size of the icon glyph. | ||
/// </summary> | ||
/// <returns> | ||
/// A non-negative value that specifies the font size, measured in pixels. | ||
/// </returns> | ||
public double FontSize | ||
{ | ||
get => (double)GetValue(FontSizeProperty); | ||
set => SetValue(FontSizeProperty, value); | ||
} | ||
|
||
/// <summary> | ||
/// Identifies the <see cref="FontStyle"/> dependency property. | ||
/// </summary> | ||
public static readonly DependencyProperty FontStyleProperty = | ||
DependencyProperty.Register( | ||
nameof(FontStyle), | ||
typeof(FontStyle), | ||
typeof(FontIconSource), | ||
new PropertyMetadata(FontStyles.Normal)); | ||
|
||
/// <summary> | ||
/// Gets or sets the font style for the icon glyph. | ||
/// </summary> | ||
/// <returns> | ||
/// A named constant of the enumeration that specifies the style in which the icon glyph is rendered. | ||
/// The default is <see cref="FontStyles.Normal"/>. | ||
/// </returns> | ||
public FontStyle FontStyle | ||
{ | ||
get => (FontStyle)GetValue(FontStyleProperty); | ||
set => SetValue(FontStyleProperty, value); | ||
} | ||
|
||
/// <summary> | ||
/// Identifies the <see cref="FontWeight"/> dependency property. | ||
/// </summary> | ||
public static readonly DependencyProperty FontWeightProperty = | ||
DependencyProperty.Register( | ||
nameof(FontWeight), | ||
typeof(FontWeight), | ||
typeof(FontIconSource), | ||
new PropertyMetadata(FontWeights.Normal)); | ||
|
||
/// <summary> | ||
/// Gets or sets the thickness of the icon glyph. | ||
/// </summary> | ||
/// <returns> | ||
/// A value that specifies the thickness of the icon glyph. | ||
/// The default is <see cref="FontWeights.Normal"/>. | ||
/// </returns> | ||
public FontWeight FontWeight | ||
{ | ||
get => (FontWeight)GetValue(FontWeightProperty); | ||
set => SetValue(FontWeightProperty, value); | ||
} | ||
|
||
/// <summary> | ||
/// Identifies the <see cref="Glyph"/> dependency property. | ||
/// </summary> | ||
public static readonly DependencyProperty GlyphProperty = | ||
DependencyProperty.Register( | ||
nameof(Glyph), | ||
typeof(string), | ||
typeof(FontIconSource), | ||
new PropertyMetadata(string.Empty)); | ||
|
||
/// <summary> | ||
/// Gets or sets the character code that identifies the icon glyph. | ||
/// </summary> | ||
/// <returns> | ||
/// The hexadecimal character code for the icon glyph. | ||
/// </returns> | ||
public string Glyph | ||
{ | ||
get => (string)GetValue(GlyphProperty); | ||
set => SetValue(GlyphProperty, value); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. See LICENSE in the project root for license information. | ||
|
||
using System.Windows; | ||
using System.Windows.Media; | ||
|
||
namespace ModernWpf.Controls | ||
{ | ||
/// <summary> | ||
/// Represents the base class for an icon source. | ||
/// </summary> | ||
public class IconSource : DependencyObject | ||
{ | ||
/// <summary> | ||
/// Identifies the <see cref="Foreground"/> dependency property. | ||
/// </summary> | ||
public static readonly DependencyProperty ForegroundProperty = | ||
DependencyProperty.Register( | ||
nameof(Foreground), | ||
typeof(Brush), | ||
typeof(IconSource)); | ||
|
||
/// <summary> | ||
/// Gets or sets a brush that describes the foreground color. | ||
/// </summary> | ||
/// <returns> | ||
/// The brush that paints the foreground of the control. The default is <see langword="null"/>, (a null brush) which is | ||
/// evaluated as Transparent for rendering. | ||
/// </returns> | ||
public Brush Foreground | ||
{ | ||
get => (Brush)GetValue(ForegroundProperty); | ||
set => SetValue(ForegroundProperty, value); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. See LICENSE in the project root for license information. | ||
|
||
using System.Windows; | ||
using System.Windows.Media; | ||
|
||
namespace ModernWpf.Controls | ||
{ | ||
/// <summary> | ||
/// Represents an icon source that uses a vector path as its content. | ||
/// </summary> | ||
public class PathIconSource : IconSource | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="PathIconSource"/> class. | ||
/// </summary> | ||
public PathIconSource() | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Identifies the <see cref="Data"/> dependency property. | ||
/// </summary> | ||
public static readonly DependencyProperty DataProperty = | ||
DependencyProperty.Register( | ||
nameof(Data), | ||
typeof(Geometry), | ||
typeof(PathIconSource)); | ||
|
||
/// <summary> | ||
/// Gets or sets a <see cref="Geometry"/>. | ||
/// </summary> | ||
/// <returns> | ||
/// A description of the shape to be drawn. | ||
/// </returns> | ||
public Geometry Data | ||
{ | ||
get => (Geometry)GetValue(DataProperty); | ||
set => SetValue(DataProperty, value); | ||
} | ||
} | ||
} |
Oops, something went wrong.