-
-
Notifications
You must be signed in to change notification settings - Fork 762
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added new icon element (and markup) - DrawingBrushIcon. New constants for NavigationLeftCompact #1061
base: main
Are you sure you want to change the base?
Added new icon element (and markup) - DrawingBrushIcon. New constants for NavigationLeftCompact #1061
Changes from all commits
abf17e6
d86b0c5
9281c43
7d1a0f2
df9ee46
5aa126e
4cb69eb
e90f5f0
c59d8f6
ef1f7eb
3e2d042
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,89 @@ | ||||||||
// This Source Code Form is subject to the terms of the MIT License. | ||||||||
// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT. | ||||||||
// Copyright (C) Leszek Pomianowski and WPF UI Contributors. | ||||||||
// All Rights Reserved. | ||||||||
|
||||||||
|
||||||||
using System.Windows.Controls; | ||||||||
|
||||||||
namespace Wpf.Ui.Controls; | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
|
||||||||
/// <summary> | ||||||||
/// Represents an icon that uses an DrawingBrush as its content. | ||||||||
/// </summary> | ||||||||
public class DrawingBrushIcon : IconElement | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing docs for the public API |
||||||||
{ | ||||||||
/// <summary> | ||||||||
/// Gets or sets <see cref="Icon"/> | ||||||||
/// </summary> | ||||||||
public DrawingBrush Icon | ||||||||
{ | ||||||||
get { return (DrawingBrush)GetValue(IconProperty); } | ||||||||
set { SetValue(IconProperty, value); } | ||||||||
} | ||||||||
|
||||||||
/// <summary>Identifies the <see cref="Icon"/> dependency property.</summary> | ||||||||
public static readonly DependencyProperty IconProperty = DependencyProperty.Register( | ||||||||
nameof(Icon), | ||||||||
typeof(DrawingBrush), | ||||||||
typeof(DrawingBrushIcon), | ||||||||
new PropertyMetadata(default(DrawingBrush), OnIconChanged)); | ||||||||
|
||||||||
private static void OnIconChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) | ||||||||
{ | ||||||||
var self = (DrawingBrushIcon)d; | ||||||||
if (self.Border is null) | ||||||||
return; | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing brackets according to the .editorconfig |
||||||||
|
||||||||
self.Border.Background = e.NewValue as DrawingBrush; | ||||||||
} | ||||||||
|
||||||||
/// <summary> | ||||||||
/// Gets or sets <see cref="Size"/> | ||||||||
/// </summary> | ||||||||
public double Size | ||||||||
{ | ||||||||
get { return (double)GetValue(SizeProperty); } | ||||||||
set { SetValue(SizeProperty, value); } | ||||||||
} | ||||||||
|
||||||||
/// <summary>Identifies the <see cref="Size"/> dependency property.</summary> | ||||||||
public static readonly DependencyProperty SizeProperty = DependencyProperty.Register( | ||||||||
nameof(Size), | ||||||||
typeof(double), | ||||||||
typeof(DrawingBrushIcon), | ||||||||
new PropertyMetadata(16.0, OnIconSizeChanged)); | ||||||||
|
||||||||
private static void OnIconSizeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) | ||||||||
{ | ||||||||
var self = (DrawingBrushIcon)d; | ||||||||
if (self.Border is null) | ||||||||
{ | ||||||||
return; | ||||||||
} | ||||||||
|
||||||||
if (double.TryParse(e.NewValue?.ToString(), out double dblValue)) | ||||||||
{ | ||||||||
self.Border.Width = dblValue; | ||||||||
self.Border.Height = dblValue; | ||||||||
} | ||||||||
} | ||||||||
|
||||||||
protected Border? Border; | ||||||||
|
||||||||
protected override UIElement InitializeChildren() | ||||||||
{ | ||||||||
Border = new Border() | ||||||||
{ | ||||||||
HorizontalAlignment = HorizontalAlignment.Stretch, | ||||||||
Background = Icon, | ||||||||
Width = Size, | ||||||||
Height = Size | ||||||||
}; | ||||||||
|
||||||||
Viewbox viewbox = new Viewbox(); | ||||||||
viewbox.Child = Border; | ||||||||
|
||||||||
return viewbox; | ||||||||
} | ||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// This Source Code Form is subject to the terms of the MIT License. | ||
// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT. | ||
// Copyright (C) Leszek Pomianowski and WPF UI Contributors. | ||
// All Rights Reserved. | ||
|
||
using System.Windows.Markup; | ||
using Wpf.Ui.Controls; | ||
|
||
namespace Wpf.Ui.Markup; | ||
|
||
[ContentProperty(nameof(Icon))] | ||
[MarkupExtensionReturnType(typeof(DrawingBrushIcon))] | ||
public class DrawingBrushIconExtension : MarkupExtension | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Formatting |
||
public DrawingBrushIconExtension(DrawingBrush icon) | ||
{ | ||
Icon = icon; | ||
} | ||
|
||
public DrawingBrushIconExtension(DrawingBrush icon, double size) | ||
: this(icon) | ||
{ | ||
Size = size; | ||
} | ||
|
||
[ConstructorArgument("icon")] | ||
public DrawingBrush Icon { get; set; } | ||
|
||
[ConstructorArgument("size")] | ||
public double Size { get; set; } = 16; | ||
|
||
public override object ProvideValue(IServiceProvider serviceProvider) | ||
{ | ||
var drawingBrushIcon = new DrawingBrushIcon { Icon = Icon, Size = Size }; | ||
|
||
return drawingBrushIcon; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.