add:新控件

This commit is contained in:
PrefacedCorg
2026-04-13 23:53:59 +08:00
parent d52ae90b56
commit b64b0a3618
3 changed files with 151 additions and 18 deletions
+38
View File
@@ -0,0 +1,38 @@
<UserControl x:Class="Ink_Canvas.Controls.ToolMenuButton"
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"
MouseLeave="ButtonPanel_MouseLeave"
MouseUp="ButtonPanel_MouseUp"
Background="Transparent"
Orientation="Vertical"
HorizontalAlignment="Center"
Height="38" Width="32"
Margin="0">
<Image x:Name="ButtonImage"
Margin="0,4,0,2"
Height="19" Width="19"
RenderOptions.BitmapScalingMode="HighQuality">
<Image.Source>
<DrawingImage>
<DrawingImage.Drawing>
<DrawingGroup ClipGeometry="M0,0 V24 H24 V0 H0 Z">
<GeometryDrawing x:Name="IconGeometryInternal"
Brush="{DynamicResource IconForeground}" />
</DrawingGroup>
</DrawingImage.Drawing>
</DrawingImage>
</Image.Source>
</Image>
<Label x:Name="LabelControl"
FontSize="8"
HorizontalAlignment="Center"
Foreground="{DynamicResource FloatBarForeground}" />
</ikw:SimpleStackPanel>
</UserControl>
+95
View File
@@ -0,0 +1,95 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
namespace Ink_Canvas.Controls
{
public partial class ToolMenuButton : UserControl
{
public static readonly DependencyProperty LabelProperty = DependencyProperty.Register(
nameof(Label), typeof(string), typeof(ToolMenuButton),
new PropertyMetadata(string.Empty, OnLabelChanged));
private static void OnLabelChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var button = (ToolMenuButton)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 IconGeometryProperty = DependencyProperty.Register(
nameof(IconGeometry), typeof(string), typeof(ToolMenuButton),
new PropertyMetadata(string.Empty, OnIconGeometryChanged));
private static void OnIconGeometryChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var button = (ToolMenuButton)d;
if (e.NewValue is string geometry && !string.IsNullOrEmpty(geometry) && button.IconGeometryInternal != null)
{
button.IconGeometryInternal.Geometry = Geometry.Parse(geometry);
}
}
public string IconGeometry
{
get => (string)GetValue(IconGeometryProperty);
set => SetValue(IconGeometryProperty, value);
}
public static readonly DependencyProperty IconBrushProperty = DependencyProperty.Register(
nameof(IconBrush), typeof(Brush), typeof(ToolMenuButton),
new PropertyMetadata(null, OnIconBrushChanged));
private static void OnIconBrushChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var button = (ToolMenuButton)d;
if (button.IconGeometryInternal != null)
button.IconGeometryInternal.Brush = (Brush)e.NewValue;
}
public Brush IconBrush
{
get => (Brush)GetValue(IconBrushProperty);
set => SetValue(IconBrushProperty, value);
}
public new Brush Background
{
get => ButtonPanel.Background;
set => ButtonPanel.Background = value;
}
public GeometryDrawing Icon => IconGeometryInternal;
public event MouseButtonEventHandler ButtonMouseDown;
public event MouseEventHandler ButtonMouseLeave;
public event RoutedEventHandler ButtonMouseUp;
public ToolMenuButton()
{
InitializeComponent();
}
private void ButtonPanel_MouseDown(object sender, MouseButtonEventArgs e)
{
ButtonMouseDown?.Invoke(this, e);
}
private void ButtonPanel_MouseLeave(object sender, MouseEventArgs e)
{
ButtonMouseLeave?.Invoke(this, e);
}
private void ButtonPanel_MouseUp(object sender, MouseButtonEventArgs e)
{
ButtonMouseUp?.Invoke(this, new RoutedEventArgs(e.RoutedEvent, this));
}
}
}