将自定义控件单开一个项目

This commit is contained in:
PrefacedCorg
2026-04-13 13:01:14 +08:00
parent 0a14d96e10
commit 41be1e901d
13 changed files with 57 additions and 7 deletions
-24
View File
@@ -1,24 +0,0 @@
<UserControl x:Class="Ink_Canvas.Controls.CopyButton"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ui="http://schemas.inkore.net/lib/ui/wpf/modern">
<Button x:Name="CopyButtonControl" Padding="6" Click="CopyButton_Click"
ToolTipService.ToolTip="Copy">
<Grid>
<ui:FontIcon x:Name="FontIcon_Copy" FontSize="16"
Icon="{x:Static ui:SegoeFluentIcons.Copy}" RenderTransformOrigin="0.5 0.5">
<FrameworkElement.RenderTransform>
<ScaleTransform x:Name="ScaleTransform_Copy"
ScaleX="1" ScaleY="{Binding ScaleX, RelativeSource={RelativeSource Self}}"/>
</FrameworkElement.RenderTransform>
</ui:FontIcon>
<ui:FontIcon x:Name="FontIcon_Success" FontSize="16"
Icon="{x:Static ui:SegoeFluentIcons.CheckMark}" RenderTransformOrigin="0.5 0.5">
<FrameworkElement.RenderTransform>
<ScaleTransform x:Name="ScaleTransform_Success"
ScaleX="0" ScaleY="{Binding ScaleX, RelativeSource={RelativeSource Self}}"/>
</FrameworkElement.RenderTransform>
</ui:FontIcon>
</Grid>
</Button>
</UserControl>
-115
View File
@@ -1,115 +0,0 @@
using System;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Animation;
namespace Ink_Canvas.Controls
{
public partial class CopyButton : UserControl
{
public static readonly DependencyProperty TextProperty = DependencyProperty.Register(
nameof(Text), typeof(string), typeof(CopyButton), new PropertyMetadata(string.Empty));
public string Text
{
get => (string)GetValue(TextProperty);
set => SetValue(TextProperty, value);
}
public event EventHandler Click;
public CopyButton()
{
InitializeComponent();
}
private void CopyButton_Click(object sender, RoutedEventArgs e)
{
try
{
if (!string.IsNullOrEmpty(Text))
{
Clipboard.SetText(Text);
}
ShowSuccessAnimation();
Click?.Invoke(this, EventArgs.Empty);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString(), "Unable to Perform Copy", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
private async void ShowSuccessAnimation()
{
var copyScaleAnim = new DoubleAnimation
{
To = 0,
Duration = TimeSpan.FromMilliseconds(150)
};
ScaleTransform_Copy.BeginAnimation(ScaleTransform.ScaleXProperty, copyScaleAnim);
var copyOpacityAnim = new DoubleAnimation
{
To = 0,
BeginTime = TimeSpan.FromMilliseconds(100),
Duration = TimeSpan.FromMilliseconds(10)
};
FontIcon_Copy.BeginAnimation(UIElement.OpacityProperty, copyOpacityAnim);
await Task.Delay(150);
var successScaleAnim = new DoubleAnimation
{
To = 1,
Duration = TimeSpan.FromMilliseconds(150),
EasingFunction = new BackEase { EasingMode = EasingMode.EaseOut, Amplitude = 0.2 }
};
ScaleTransform_Success.BeginAnimation(ScaleTransform.ScaleXProperty, successScaleAnim);
var successOpacityAnim = new DoubleAnimation
{
To = 1,
Duration = TimeSpan.FromMilliseconds(15)
};
FontIcon_Success.BeginAnimation(UIElement.OpacityProperty, successOpacityAnim);
await Task.Delay(1000);
ShowCopyAnimation();
}
private async void ShowCopyAnimation()
{
var successOpacityAnim = new DoubleAnimation
{
To = 0,
Duration = TimeSpan.FromMilliseconds(150)
};
FontIcon_Success.BeginAnimation(UIElement.OpacityProperty, successOpacityAnim);
await Task.Delay(150);
var copyScaleAnim = new DoubleAnimation
{
To = 1,
Duration = TimeSpan.Zero
};
ScaleTransform_Copy.BeginAnimation(ScaleTransform.ScaleXProperty, copyScaleAnim);
var copyOpacityAnim = new DoubleAnimation
{
To = 1,
Duration = TimeSpan.FromMilliseconds(150)
};
FontIcon_Copy.BeginAnimation(UIElement.OpacityProperty, copyOpacityAnim);
var successScaleAnim = new DoubleAnimation
{
To = 0,
Duration = TimeSpan.Zero
};
ScaleTransform_Success.BeginAnimation(ScaleTransform.ScaleXProperty, successScaleAnim);
}
}
}
@@ -1,26 +0,0 @@
<UserControl x:Class="Ink_Canvas.Controls.LabeledToggleSwitch"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ui="http://schemas.inkore.net/lib/ui/wpf/modern"
xmlns:ikw="http://schemas.inkore.net/lib/ui/wpf">
<ikw:SimpleStackPanel Spacing="4">
<ikw:SimpleStackPanel Orientation="Horizontal" HorizontalAlignment="Left">
<TextBlock Text="{Binding Label, RelativeSource={RelativeSource AncestorType=UserControl}}"
VerticalAlignment="Center"
Foreground="#fafafa"
FontSize="14"
Margin="0,0,16,0"/>
<ui:ToggleSwitch x:Name="ToggleSwitch"
OnContent="{Binding OnContent, RelativeSource={RelativeSource AncestorType=UserControl}}"
OffContent="{Binding OffContent, RelativeSource={RelativeSource AncestorType=UserControl}}"
IsOn="{Binding IsOn, RelativeSource={RelativeSource AncestorType=UserControl}, Mode=TwoWay}"
FontWeight="Bold"
Toggled="ToggleSwitch_Toggled"/>
</ikw:SimpleStackPanel>
<TextBlock x:Name="HintTextBlock"
Text="{Binding Hint, RelativeSource={RelativeSource AncestorType=UserControl}}"
TextWrapping="Wrap"
Foreground="#a1a1aa"
Visibility="Collapsed"/>
</ikw:SimpleStackPanel>
</UserControl>
@@ -1,96 +0,0 @@
using System.Windows;
using System.Windows.Controls;
using ui = iNKORE.UI.WPF.Modern.Controls;
namespace Ink_Canvas.Controls
{
public partial class LabeledToggleSwitch : UserControl
{
public ui.ToggleSwitch ToggleSwitchControl => ToggleSwitch;
public static readonly DependencyProperty LabelProperty = DependencyProperty.Register(
nameof(Label), typeof(string), typeof(LabeledToggleSwitch), new PropertyMetadata(string.Empty));
public string Label
{
get => (string)GetValue(LabelProperty);
set => SetValue(LabelProperty, value);
}
public static readonly DependencyProperty HintProperty = DependencyProperty.Register(
nameof(Hint), typeof(string), typeof(LabeledToggleSwitch), new PropertyMetadata(string.Empty, OnHintChanged));
public string Hint
{
get => (string)GetValue(HintProperty);
set => SetValue(HintProperty, value);
}
private static void OnHintChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (d is LabeledToggleSwitch control)
{
var hint = e.NewValue as string;
control.HintTextBlock.Visibility = string.IsNullOrEmpty(hint) ? Visibility.Collapsed : Visibility.Visible;
}
}
public static readonly DependencyProperty IsOnProperty = DependencyProperty.Register(
nameof(IsOn), typeof(bool), typeof(LabeledToggleSwitch), new PropertyMetadata(false));
public bool IsOn
{
get => (bool)GetValue(IsOnProperty);
set => SetValue(IsOnProperty, value);
}
public static readonly DependencyProperty OnContentProperty = DependencyProperty.Register(
nameof(OnContent), typeof(string), typeof(LabeledToggleSwitch), new PropertyMetadata(string.Empty));
public string OnContent
{
get => (string)GetValue(OnContentProperty);
set => SetValue(OnContentProperty, value);
}
public static readonly DependencyProperty OffContentProperty = DependencyProperty.Register(
nameof(OffContent), typeof(string), typeof(LabeledToggleSwitch), new PropertyMetadata(string.Empty));
public string OffContent
{
get => (string)GetValue(OffContentProperty);
set => SetValue(OffContentProperty, value);
}
public static readonly DependencyProperty ShowWhenProperty = DependencyProperty.Register(
nameof(ShowWhen), typeof(bool), typeof(LabeledToggleSwitch), new PropertyMetadata(true, OnShowWhenChanged));
public bool ShowWhen
{
get => (bool)GetValue(ShowWhenProperty);
set => SetValue(ShowWhenProperty, value);
}
private static void OnShowWhenChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (d is LabeledToggleSwitch control)
{
control.Visibility = (bool)e.NewValue ? Visibility.Visible : Visibility.Collapsed;
}
}
public event RoutedEventHandler Toggled;
public LabeledToggleSwitch()
{
InitializeComponent();
Visibility = ShowWhen ? Visibility.Visible : Visibility.Collapsed;
HintTextBlock.Visibility = string.IsNullOrEmpty(Hint) ? Visibility.Collapsed : Visibility.Visible;
}
private void ToggleSwitch_Toggled(object sender, RoutedEventArgs e)
{
Toggled?.Invoke(this, e);
}
}
}
@@ -1,32 +0,0 @@
<UserControl x:Class="Ink_Canvas.Controls.ToolbarImageButton"
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="45" d:DesignWidth="28">
<ikw:SimpleStackPanel Name="ButtonPanel"
MouseDown="ButtonPanel_MouseDown"
MouseLeave="ButtonPanel_MouseLeave"
MouseUp="ButtonPanel_MouseUp"
Background="Transparent" Orientation="Vertical"
HorizontalAlignment="Center" Width="28" Margin="0,-2">
<Image x:Name="ButtonImage" RenderOptions.BitmapScalingMode="HighQuality" Height="17" Margin="0,3,0,0">
<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>
<TextBlock x:Name="LabelTextBlock"
Foreground="{DynamicResource FloatBarForeground}"
FontSize="8"
Margin="0,1,0,0" TextAlignment="Center"
Style="{DynamicResource AutoFitMainToolbarLabel8}" />
</ikw:SimpleStackPanel>
</UserControl>
@@ -1,110 +0,0 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
namespace Ink_Canvas.Controls
{
public partial class ToolbarImageButton : UserControl
{
private static ToolbarImageButton _lastPressedButton;
public static readonly DependencyProperty LabelProperty = DependencyProperty.Register(
nameof(Label), typeof(string), typeof(ToolbarImageButton),
new PropertyMetadata(string.Empty, (d, e) => ((ToolbarImageButton)d).LabelTextBlock.Text = (string)e.NewValue));
public string Label
{
get => (string)GetValue(LabelProperty);
set => SetValue(LabelProperty, value);
}
public static readonly DependencyProperty IconGeometryDrawingProperty = DependencyProperty.Register(
nameof(IconGeometryDrawing), typeof(GeometryDrawing), typeof(ToolbarImageButton),
new PropertyMetadata(null, OnIconGeometryDrawingChanged));
private static void OnIconGeometryDrawingChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var button = (ToolbarImageButton)d;
if (e.NewValue is GeometryDrawing newDrawing)
{
button.IconGeometryInternal.Geometry = newDrawing.Geometry;
button.IconGeometryInternal.Brush = newDrawing.Brush;
}
}
public GeometryDrawing IconGeometryDrawing
{
get => (GeometryDrawing)GetValue(IconGeometryDrawingProperty);
set => SetValue(IconGeometryDrawingProperty, value);
}
public GeometryDrawing Icon => IconGeometryInternal;
public GeometryDrawing GeometryDrawing => IconGeometryInternal;
public static readonly DependencyProperty IconBrushProperty = DependencyProperty.Register(
nameof(IconBrush), typeof(Brush), typeof(ToolbarImageButton),
new PropertyMetadata(null, (d, e) => ((ToolbarImageButton)d).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 event MouseButtonEventHandler ButtonMouseDown;
public event MouseEventHandler ButtonMouseLeave;
public event RoutedEventHandler ButtonMouseUp;
public ToolbarImageButton()
{
InitializeComponent();
ButtonPanel.Background = Brushes.Transparent;
IsEnabledChanged += ToolbarImageButton_IsEnabledChanged;
}
private void ToolbarImageButton_IsEnabledChanged(object sender, DependencyPropertyChangedEventArgs e)
{
var isEnabled = (bool)e.NewValue;
ButtonImage.Opacity = isEnabled ? 1.0 : 0.5;
LabelTextBlock.Opacity = isEnabled ? 1.0 : 0.5;
ButtonPanel.IsEnabled = isEnabled;
}
private void ButtonPanel_MouseDown(object sender, MouseButtonEventArgs e)
{
if (!IsEnabled) return;
if (_lastPressedButton != null && _lastPressedButton != this)
{
_lastPressedButton.Background = Brushes.Transparent;
}
_lastPressedButton = this;
ButtonPanel.Background = new SolidColorBrush(Color.FromArgb(28, 24, 24, 27));
ButtonMouseDown?.Invoke(this, e);
}
private void ButtonPanel_MouseLeave(object sender, MouseEventArgs e)
{
if (!IsEnabled) return;
ButtonMouseLeave?.Invoke(this, e);
}
private void ButtonPanel_MouseUp(object sender, MouseButtonEventArgs e)
{
if (!IsEnabled) return;
if (_lastPressedButton == this)
{
ButtonPanel.Background = Brushes.Transparent;
_lastPressedButton = null;
}
ButtonMouseUp?.Invoke(this, new RoutedEventArgs(e.RoutedEvent, this));
}
}
}