优化
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
<UserControl x:Class="Ink_Canvas.Controls.GeometryButton"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:ikw="http://schemas.inkore.net/lib/ui/wpf"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="38" d:DesignWidth="32">
|
||||
<ikw:SimpleStackPanel x:Name="ButtonPanel"
|
||||
MouseDown="ButtonPanel_MouseDown"
|
||||
MouseUp="ButtonPanel_MouseUp"
|
||||
Background="Transparent"
|
||||
Orientation="Vertical"
|
||||
Height="38" Width="32"
|
||||
Margin="0,0,0,0">
|
||||
<Image x:Name="ButtonImage"
|
||||
RenderOptions.BitmapScalingMode="HighQuality"
|
||||
Margin="0,4,0,2" Height="19" Width="19" />
|
||||
<Label x:Name="LabelControl"
|
||||
FontSize="8"
|
||||
HorizontalAlignment="Center" />
|
||||
</ikw:SimpleStackPanel>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,62 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace Ink_Canvas.Controls
|
||||
{
|
||||
public partial class GeometryButton : UserControl
|
||||
{
|
||||
public static readonly DependencyProperty LabelProperty = DependencyProperty.Register(
|
||||
nameof(Label), typeof(string), typeof(GeometryButton),
|
||||
new PropertyMetadata(string.Empty, OnLabelChanged));
|
||||
|
||||
private static void OnLabelChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var button = (GeometryButton)d;
|
||||
if (button.LabelControl != null)
|
||||
button.LabelControl.Content = (string)e.NewValue;
|
||||
}
|
||||
|
||||
public string Label
|
||||
{
|
||||
get => (string)GetValue(LabelProperty);
|
||||
set => SetValue(LabelProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty IconSourceProperty = DependencyProperty.Register(
|
||||
nameof(IconSource), typeof(ImageSource), typeof(GeometryButton),
|
||||
new PropertyMetadata(null, OnIconSourceChanged));
|
||||
|
||||
private static void OnIconSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var button = (GeometryButton)d;
|
||||
if (button.ButtonImage != null)
|
||||
button.ButtonImage.Source = (ImageSource)e.NewValue;
|
||||
}
|
||||
|
||||
public ImageSource IconSource
|
||||
{
|
||||
get => (ImageSource)GetValue(IconSourceProperty);
|
||||
set => SetValue(IconSourceProperty, value);
|
||||
}
|
||||
|
||||
public event MouseButtonEventHandler ButtonMouseDown;
|
||||
public event MouseButtonEventHandler ButtonMouseUp;
|
||||
|
||||
public GeometryButton()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void ButtonPanel_MouseDown(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
ButtonMouseDown?.Invoke(this, e);
|
||||
}
|
||||
|
||||
private void ButtonPanel_MouseUp(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
ButtonMouseUp?.Invoke(this, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user