I want to create a custom button based on ButtonAdv.
I need to add DependencyProperty and override some default values.
Idea is to have a button that will display a badge with the button's key property value.
So if I set the Key property to "F1" the badge will display "F1".
I've got the badge working, but I can't override the default values of the control. For example, I'd like to set the default margin and padding.
The code below is based on https://www.syncfusion.com/feedback/21778/add-shortcut-property-that-will-allow-calling-command-by-pressing-specific-key-hot
using System.Windows;
using System.Windows.Input;
using Syncfusion.Windows.Controls.Notification;
using Syncfusion.Windows.Tools.Controls;
namespace Test.Desktop.Wpf.Controls
{
public class BetterButton:ButtonAdv
{
public static readonly DependencyProperty KeyProperty = DependencyProperty.Register(nameof(Key), typeof(Key), typeof(BetterButton), new UIPropertyMetadata(Key.None, OnKeyPropertyChanged));
private static void OnKeyPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if(!(d is BetterButton dd)) return;
dd.Badge.Content = dd.Key.ToString();
}
public BetterButton()
{
VerticalAlignment = VerticalAlignment.Center;
HorizontalAlignment = HorizontalAlignment.Center;
Margin = new Thickness(10, 0,10,0);
Padding = new Thickness(10);
SmallIcon = null;
LargeIcon = null;
Badge = new SfBadge
{
Content = Key.ToString(),
HorizontalAnchor = BadgeAnchor.Inside,
HorizontalAlignment = HorizontalAlignment.Left,
HorizontalPosition = 0.05,
VerticalAnchor = BadgeAnchor.Outside,
Shape = BadgeShape.None,
FontSize = 10
};
SfBadge.SetBadge(this, Badge);
}
public Key Key
{
get => (Key)this.GetValue(KeyProperty);
set => this.SetValue(KeyProperty, value);
}
public SfBadge Badge { get; }
}
}