add:按钮添加圆角和阴影
This commit is contained in:
@@ -6,33 +6,37 @@
|
||||
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>
|
||||
<Border x:Name="ButtonBorder"
|
||||
CornerRadius="5"
|
||||
Background="Transparent">
|
||||
<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>
|
||||
</Border>
|
||||
</UserControl>
|
||||
@@ -9,6 +9,7 @@ namespace Ink_Canvas.Controls
|
||||
{
|
||||
private Geometry _pendingGeometry;
|
||||
private Brush _pendingBrush;
|
||||
private static ToolMenuButton _lastPressedButton;
|
||||
|
||||
public static readonly DependencyProperty LabelProperty = DependencyProperty.Register(
|
||||
nameof(Label), typeof(string), typeof(ToolMenuButton),
|
||||
@@ -68,8 +69,8 @@ namespace Ink_Canvas.Controls
|
||||
|
||||
public new Brush Background
|
||||
{
|
||||
get => ButtonPanel.Background;
|
||||
set => ButtonPanel.Background = value;
|
||||
get => ButtonBorder.Background;
|
||||
set => ButtonBorder.Background = value;
|
||||
}
|
||||
|
||||
public GeometryDrawing Icon
|
||||
@@ -90,6 +91,7 @@ namespace Ink_Canvas.Controls
|
||||
{
|
||||
InitializeComponent();
|
||||
Loaded += ToolMenuButton_Loaded;
|
||||
ButtonBorder.Background = Brushes.Transparent;
|
||||
}
|
||||
|
||||
private void ToolMenuButton_Loaded(object sender, RoutedEventArgs e)
|
||||
@@ -105,16 +107,35 @@ namespace Ink_Canvas.Controls
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
private void ButtonPanel_MouseLeave(object sender, MouseEventArgs e)
|
||||
{
|
||||
if (!IsEnabled) return;
|
||||
if (_lastPressedButton == this)
|
||||
{
|
||||
ButtonBorder.Background = Brushes.Transparent;
|
||||
_lastPressedButton = null;
|
||||
}
|
||||
ButtonMouseLeave?.Invoke(this, 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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user