add:按钮添加圆角和阴影

This commit is contained in:
PrefacedCorg
2026-05-02 15:34:18 +08:00
parent ed7157163c
commit 09713f70bf
2 changed files with 58 additions and 33 deletions
+33 -29
View File
@@ -6,33 +6,37 @@
xmlns:ikw="http://schemas.inkore.net/lib/ui/wpf" xmlns:ikw="http://schemas.inkore.net/lib/ui/wpf"
mc:Ignorable="d" mc:Ignorable="d"
d:DesignHeight="38" d:DesignWidth="32"> d:DesignHeight="38" d:DesignWidth="32">
<ikw:SimpleStackPanel x:Name="ButtonPanel" <Border x:Name="ButtonBorder"
MouseDown="ButtonPanel_MouseDown" CornerRadius="5"
MouseLeave="ButtonPanel_MouseLeave" Background="Transparent">
MouseUp="ButtonPanel_MouseUp" <ikw:SimpleStackPanel x:Name="ButtonPanel"
Background="Transparent" MouseDown="ButtonPanel_MouseDown"
Orientation="Vertical" MouseLeave="ButtonPanel_MouseLeave"
HorizontalAlignment="Center" MouseUp="ButtonPanel_MouseUp"
Height="38" Width="32" Background="Transparent"
Margin="0"> Orientation="Vertical"
<Image x:Name="ButtonImage" HorizontalAlignment="Center"
Margin="0,4,0,2" Height="38" Width="32"
Height="19" Width="19" Margin="0">
RenderOptions.BitmapScalingMode="HighQuality"> <Image x:Name="ButtonImage"
<Image.Source> Margin="0,4,0,2"
<DrawingImage> Height="19" Width="19"
<DrawingImage.Drawing> RenderOptions.BitmapScalingMode="HighQuality">
<DrawingGroup ClipGeometry="M0,0 V24 H24 V0 H0 Z"> <Image.Source>
<GeometryDrawing x:Name="IconGeometryInternal" <DrawingImage>
Brush="{DynamicResource IconForeground}" /> <DrawingImage.Drawing>
</DrawingGroup> <DrawingGroup ClipGeometry="M0,0 V24 H24 V0 H0 Z">
</DrawingImage.Drawing> <GeometryDrawing x:Name="IconGeometryInternal"
</DrawingImage> Brush="{DynamicResource IconForeground}" />
</Image.Source> </DrawingGroup>
</Image> </DrawingImage.Drawing>
<Label x:Name="LabelControl" </DrawingImage>
FontSize="8" </Image.Source>
HorizontalAlignment="Center" </Image>
Foreground="{DynamicResource FloatBarForeground}" /> <Label x:Name="LabelControl"
</ikw:SimpleStackPanel> FontSize="8"
HorizontalAlignment="Center"
Foreground="{DynamicResource FloatBarForeground}" />
</ikw:SimpleStackPanel>
</Border>
</UserControl> </UserControl>
+23 -2
View File
@@ -9,6 +9,7 @@ namespace Ink_Canvas.Controls
{ {
private Geometry _pendingGeometry; private Geometry _pendingGeometry;
private Brush _pendingBrush; private Brush _pendingBrush;
private static ToolMenuButton _lastPressedButton;
public static readonly DependencyProperty LabelProperty = DependencyProperty.Register( public static readonly DependencyProperty LabelProperty = DependencyProperty.Register(
nameof(Label), typeof(string), typeof(ToolMenuButton), nameof(Label), typeof(string), typeof(ToolMenuButton),
@@ -68,8 +69,8 @@ namespace Ink_Canvas.Controls
public new Brush Background public new Brush Background
{ {
get => ButtonPanel.Background; get => ButtonBorder.Background;
set => ButtonPanel.Background = value; set => ButtonBorder.Background = value;
} }
public GeometryDrawing Icon public GeometryDrawing Icon
@@ -90,6 +91,7 @@ namespace Ink_Canvas.Controls
{ {
InitializeComponent(); InitializeComponent();
Loaded += ToolMenuButton_Loaded; Loaded += ToolMenuButton_Loaded;
ButtonBorder.Background = Brushes.Transparent;
} }
private void ToolMenuButton_Loaded(object sender, RoutedEventArgs e) private void ToolMenuButton_Loaded(object sender, RoutedEventArgs e)
@@ -105,16 +107,35 @@ namespace Ink_Canvas.Controls
private void ButtonPanel_MouseDown(object sender, MouseButtonEventArgs e) private void ButtonPanel_MouseDown(object sender, MouseButtonEventArgs e)
{ {
if (!IsEnabled) return;
if (_lastPressedButton != null && _lastPressedButton != this)
{
_lastPressedButton.ButtonBorder.Background = Brushes.Transparent;
}
_lastPressedButton = this;
ButtonBorder.Background = new SolidColorBrush(Color.FromArgb(80, 24, 24, 27));
ButtonMouseDown?.Invoke(this, e); ButtonMouseDown?.Invoke(this, e);
} }
private void ButtonPanel_MouseLeave(object sender, MouseEventArgs e) private void ButtonPanel_MouseLeave(object sender, MouseEventArgs e)
{ {
if (!IsEnabled) return;
if (_lastPressedButton == this)
{
ButtonBorder.Background = Brushes.Transparent;
_lastPressedButton = null;
}
ButtonMouseLeave?.Invoke(this, e); ButtonMouseLeave?.Invoke(this, e);
} }
private void ButtonPanel_MouseUp(object sender, MouseButtonEventArgs e) private void ButtonPanel_MouseUp(object sender, MouseButtonEventArgs e)
{ {
if (!IsEnabled) return;
if (_lastPressedButton == this)
{
ButtonBorder.Background = Brushes.Transparent;
_lastPressedButton = null;
}
ButtonMouseUp?.Invoke(this, e); ButtonMouseUp?.Invoke(this, e);
} }
} }