优化
This commit is contained in:
@@ -113,6 +113,34 @@ namespace Ink_Canvas.Controls
|
||||
set => LabelTextBlock.Foreground = value;
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty IsEnabledBindingProperty = DependencyProperty.Register(
|
||||
nameof(IsEnabledBinding), typeof(bool?), typeof(BoardToolbarButton),
|
||||
new PropertyMetadata(null, OnIsEnabledBindingChanged));
|
||||
|
||||
private static void OnIsEnabledBindingChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var button = (BoardToolbarButton)d;
|
||||
if (e.NewValue is bool isEnabled)
|
||||
{
|
||||
button.IsEnabled = isEnabled;
|
||||
button.UpdateIconOpacity(isEnabled);
|
||||
}
|
||||
}
|
||||
|
||||
public bool? IsEnabledBinding
|
||||
{
|
||||
get => (bool?)GetValue(IsEnabledBindingProperty);
|
||||
set => SetValue(IsEnabledBindingProperty, value);
|
||||
}
|
||||
|
||||
private void UpdateIconOpacity(bool isEnabled)
|
||||
{
|
||||
if (ButtonImage != null)
|
||||
{
|
||||
ButtonImage.Opacity = isEnabled ? 1.0 : 0.4;
|
||||
}
|
||||
}
|
||||
|
||||
public BoardToolbarButton()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
@@ -65,7 +65,7 @@ namespace Ink_Canvas.Controls
|
||||
set => SetValue(LabelFontSizeProperty, value);
|
||||
}
|
||||
|
||||
public event RoutedEventHandler ButtonMouseUp;
|
||||
public event MouseButtonEventHandler ButtonMouseUp;
|
||||
|
||||
public QuickPanelButton()
|
||||
{
|
||||
@@ -74,7 +74,7 @@ namespace Ink_Canvas.Controls
|
||||
|
||||
private void ButtonPanel_MouseUp(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
ButtonMouseUp?.Invoke(this, new RoutedEventArgs(e.RoutedEvent, this));
|
||||
ButtonMouseUp?.Invoke(this, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ namespace Ink_Canvas.Controls
|
||||
|
||||
public event MouseButtonEventHandler ButtonMouseDown;
|
||||
public event MouseEventHandler ButtonMouseLeave;
|
||||
public event RoutedEventHandler ButtonMouseUp;
|
||||
public event MouseButtonEventHandler ButtonMouseUp;
|
||||
|
||||
public ToolMenuButton()
|
||||
{
|
||||
@@ -115,7 +115,7 @@ namespace Ink_Canvas.Controls
|
||||
|
||||
private void ButtonPanel_MouseUp(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
ButtonMouseUp?.Invoke(this, new RoutedEventArgs(e.RoutedEvent, this));
|
||||
ButtonMouseUp?.Invoke(this, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ namespace Ink_Canvas.Controls
|
||||
|
||||
public event MouseButtonEventHandler ButtonMouseDown;
|
||||
public event MouseEventHandler ButtonMouseLeave;
|
||||
public event RoutedEventHandler ButtonMouseUp;
|
||||
public event MouseButtonEventHandler ButtonMouseUp;
|
||||
|
||||
public ToolbarImageButton()
|
||||
{
|
||||
@@ -104,7 +104,7 @@ namespace Ink_Canvas.Controls
|
||||
ButtonPanel.Background = Brushes.Transparent;
|
||||
_lastPressedButton = null;
|
||||
}
|
||||
ButtonMouseUp?.Invoke(this, new RoutedEventArgs(e.RoutedEvent, this));
|
||||
ButtonMouseUp?.Invoke(this, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user