using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
namespace CustomWindow
{
public partial class WindowButton : Button
{
#region DependencyProperties
///
/// Button content
/// Base button's content property is hidden
///
public new object Content
{
get => GetValue(ContentProperty);
set { SetValue(ContentProperty, value); RefreshContent(); }
}
public new static readonly DependencyProperty ContentProperty =
DependencyProperty.Register("Content", typeof(object), typeof(WindowButton), new UIPropertyMetadata());
///
/// Disabled button content
///
public object ContentDisabled
{
get => GetValue(ContentDisabledProperty);
set { SetValue(ContentDisabledProperty, value); RefreshContent(); }
}
public static readonly DependencyProperty ContentDisabledProperty =
DependencyProperty.Register("ContentDisabled", typeof(object), typeof(WindowButton), new UIPropertyMetadata());
///
/// Corner radius of the button
///
public CornerRadius CornerRadius
{
get => (CornerRadius)GetValue(CornerRadiusDPProperty);
set => SetValue(CornerRadiusDPProperty, value);
}
public static readonly DependencyProperty CornerRadiusDPProperty =
DependencyProperty.Register("CornerRadius", typeof(CornerRadius), typeof(WindowButton), new UIPropertyMetadata(new CornerRadius()));
[System.ComponentModel.Bindable(true)]
public object ActiveContent
{
get => GetValue(ActiveContentProperty);
set => SetValue(ActiveContentProperty, value);
}
public static readonly DependencyProperty ActiveContentProperty =
DependencyProperty.Register("ActiveContent", typeof(object), typeof(WindowButton), new UIPropertyMetadata());
#endregion
///
/// Button default Background
///
public virtual Brush BackgroundDefaultValue => (Brush)FindResource("DefaultBackgroundBrush");
///
/// Instantiate WindowButton class
///
public WindowButton()
{
InitializeComponent();
IsEnabledChanged += (s, e) => RefreshContent();
}
///
/// Set's the content of the button according to the current 'IsEnabled' state of the button
///
protected void RefreshContent()
{
// Button is enabled
if (IsEnabled)
ActiveContent = Content;
else
ActiveContent = ContentDisabled;
}
}
}