🧡优化拾色器

This commit is contained in:
BookerLiu
2023-04-14 17:44:39 +08:00
parent 29bb799f11
commit c34142923c
2 changed files with 118 additions and 14 deletions

View File

@@ -5,6 +5,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:GeekDesk.Control.Windows"
xmlns:hc="https://handyorg.github.io/handycontrol"
xmlns:xf="clr-namespace:XamlFlair;assembly=XamlFlair.WPF"
WindowStyle="None"
AllowsTransparency="True"
Background="Transparent"
@@ -14,15 +15,59 @@
Background="White"
Height="385"
Width="228">
<StackPanel>
<Border MouseDown="DragMove"
<Grid>
<TextBlock Panel.ZIndex="1000" Text="❤❤❤"
x:Name="CopySuccess"
Visibility="Collapsed"
xf:Animations.Primary="{xf:Animate BasedOn={StaticResource FadeInAndSlideFromBottom}, Duration=400, Event=None}"
xf:Animations.PrimaryBinding="{Binding CopyAnimation}"
Margin="138,300,0,0"
/>
<Button Height="32"
BorderThickness="0" Content="复 制"
Panel.ZIndex="999"
Margin="122,329,0,0"
HorizontalAlignment="Left"
Background="#BF8EF6"
Click="MyColorPicker_Confirmed"
VerticalAlignment="Top" Width="80"
>
<Button.Style>
<Style TargetType="Button" BasedOn="{StaticResource Btn1}">
<Style.Triggers>
<Trigger Property="IsPressed" Value="true">
<Setter Property="Opacity" Value="1"/>
</Trigger>
</Style.Triggers>
</Style>
</Button.Style>
</Button>
<Button Height="32"
BorderThickness="0" Content="关 闭"
Panel.ZIndex="999" Margin="26,329,0,0"
Background="#EEEEEE"
Click="MyColorPicker_Canceled"
HorizontalAlignment="Left"
VerticalAlignment="Top" Width="80"
>
<Button.Style>
<Style TargetType="Button" BasedOn="{StaticResource Btn1}">
<Style.Triggers>
<Trigger Property="IsPressed" Value="true">
<Setter Property="Opacity" Value="1"/>
</Trigger>
</Style.Triggers>
</Style>
</Button.Style>
</Button>
<StackPanel>
<Border MouseDown="DragMove"
VerticalAlignment="Top"
CornerRadius="8,8,0,0"
Height="20"
Background="White"
>
<Button Width="18" Height="18"
<Button Width="18" Height="18"
hc:IconElement.Geometry="{StaticResource ErrorGeometry}"
Padding="0"
Background="Transparent"
@@ -33,17 +78,15 @@
MouseEnter="Button_MouseEnter"
MouseLeave="Button_MouseLeave"
VerticalAlignment="Center">
</Button>
</Border>
<hc:ColorPicker HorizontalAlignment="Center"
</Button>
</Border>
<hc:ColorPicker HorizontalAlignment="Center"
VerticalAlignment="Bottom"
SelectedColorChanged="MyColorPicker_SelectedColorChanged"
x:Name="MyColorPicker"
Confirmed="MyColorPicker_Confirmed"
Canceled="MyColorPicker_Canceled"
ToggleButton.Checked="MyColorPicker_Checked"/>
</StackPanel>
</StackPanel>
</Grid>
</Border>
</Window>

View File

@@ -1,5 +1,8 @@
using GeekDesk.Interface;
using GeekDesk.Util;
using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
@@ -14,10 +17,33 @@ namespace GeekDesk.Control.Windows
public partial class GlobalColorPickerWindow : IWindowCommon
{
PixelColorPickerWindow colorPickerWindow = null;
class PrivateDataContext : INotifyPropertyChanged
{
private bool copyAnimation = false;
public bool CopyAnimation
{
set
{
copyAnimation = value;
OnPropertyChanged("CopyAnimation");
}
get { return copyAnimation; }
}
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
public GlobalColorPickerWindow()
{
this.Topmost = true;
InitializeComponent();
this.DataContext = new PrivateDataContext();
}
public void OnKeyDown(object sender, KeyEventArgs e)
@@ -35,14 +61,26 @@ namespace GeekDesk.Control.Windows
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void MyColorPicker_Canceled(object sender, EventArgs e)
private void MyColorPicker_Canceled(object sender, RoutedEventArgs e)
{
MyColorPickerClose();
}
private void MyColorPicker_Confirmed(object sender, HandyControl.Data.FunctionEventArgs<Color> e)
private void MyColorPicker_Confirmed(object sender, RoutedEventArgs e)
{
CopySuccess.Visibility = Visibility.Visible;
PrivateDataContext pdc = this.DataContext as PrivateDataContext;
pdc.CopyAnimation = true;
new Thread(() =>
{
Thread.Sleep(400);
this.Dispatcher.Invoke(() =>
{
pdc.CopyAnimation = false;
CopySuccess.Visibility = Visibility.Collapsed;
});
}).Start();
Color c = MyColorPicker.SelectedBrush.Color;
Clipboard.SetData(DataFormats.Text, string.Format("#{0:X2}{1:X2}{2:X2}{3:X2}", c.A, c.R, c.G, c.B));
Clipboard.SetData(DataFormats.Text, string.Format("#{0:X2}{1:X2}{2:X2}", c.R, c.G, c.B));
}
/// <summary>
@@ -148,5 +186,28 @@ namespace GeekDesk.Control.Windows
{
this.Close();
}
private ICommand _hideCommand;
public ICommand HideCommand
{
get
{
if (_hideCommand == null)
{
_hideCommand = new RelayCommand(
p =>
{
return true;
},
p =>
{
//CopySuccess.Visibility = Visibility.Collapsed;
});
}
return _hideCommand;
}
}
}
}