修复拾色器bug

This commit is contained in:
liufei
2022-03-25 17:57:01 +08:00
parent 679a0edbed
commit b0066939dd
2 changed files with 57 additions and 15 deletions

View File

@@ -3,7 +3,6 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:GeekDesk.Control.UserControls.Config"
xmlns:hc="https://handyorg.github.io/handycontrol" xmlns:hc="https://handyorg.github.io/handycontrol"
mc:Ignorable="d" mc:Ignorable="d"
Background="Transparent" Background="Transparent"
@@ -133,20 +132,27 @@
<hc:UniformSpacingPanel Spacing="10" Grid.ColumnSpan="4"> <hc:UniformSpacingPanel Spacing="10" Grid.ColumnSpan="4">
<TextBlock VerticalAlignment="Center" Text="图标字体颜色:" /> <TextBlock VerticalAlignment="Center" Text="图标字体颜色:" />
<TextBlock VerticalAlignment="Center" Text="{Binding TextColor}" Width="100"/> <TextBlock VerticalAlignment="Center" Text="{Binding TextColor}" Width="100"/>
<Button Content="选择" Click="ColorButton_Click"/> <Button Content="选择" Margin="0,-10,0,0" Click="ColorButton_Click"/>
</hc:UniformSpacingPanel> </hc:UniformSpacingPanel>
</StackPanel> </StackPanel>
</Grid> </Grid>
<StackPanel x:Name="ColorPanel" Visibility="Collapsed" VerticalAlignment="Center"> <StackPanel x:Name="ColorPanel" Panel.ZIndex="1"
Visibility="Collapsed"
Height="500"
Width="450"
VerticalAlignment="Center">
<StackPanel.Background> <StackPanel.Background>
<SolidColorBrush Color="AliceBlue" Opacity="0"/> <SolidColorBrush Color="AliceBlue" Opacity="0"/>
</StackPanel.Background> </StackPanel.Background>
<hc:ColorPicker
Name="ColorPicker" <hc:ColorPicker Name="MyColorPicker"
Canceled="ColorPicker_Canceled" ToggleButton.Checked="MyColorPicker_Checked"
SelectedColorChanged="ColorPicker_SelectedColorChanged"/> Canceled="MyColorPicker_Canceled"
Confirmed="MyColorPicker_Confirmed"
SelectedColorChanged="MyColorPicker_SelectedColorChanged"/>
</StackPanel> </StackPanel>
</Grid> </Grid>
</UserControl> </UserControl>

View File

@@ -6,13 +6,17 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data; using System.Windows.Data;
using System.Windows.Documents; using System.Windows.Documents;
using System.Windows.Input; using System.Windows.Input;
using System.Windows.Interop;
using System.Windows.Media; using System.Windows.Media;
using System.Windows.Media.Imaging; using System.Windows.Media.Imaging;
using System.Windows.Navigation; using System.Windows.Navigation;
@@ -27,6 +31,8 @@ namespace GeekDesk.Control.UserControls.Config
{ {
private static AppConfig appConfig = MainWindow.appData.AppConfig; private static AppConfig appConfig = MainWindow.appData.AppConfig;
private System.Windows.Controls.Primitives.ToggleButton toggleButton = null;
public ThemeControl() public ThemeControl()
{ {
InitializeComponent(); InitializeComponent();
@@ -39,7 +45,7 @@ namespace GeekDesk.Control.UserControls.Config
/// <param name="e"></param> /// <param name="e"></param>
private void BGButton_Click(object sender, RoutedEventArgs e) private void BGButton_Click(object sender, RoutedEventArgs e)
{ {
try try
{ {
OpenFileDialog ofd = new OpenFileDialog OpenFileDialog ofd = new OpenFileDialog
@@ -84,16 +90,24 @@ namespace GeekDesk.Control.UserControls.Config
ColorPanel.Visibility = Visibility.Visible; ColorPanel.Visibility = Visibility.Visible;
} }
private void ColorPicker_Canceled(object sender, EventArgs e) /// <summary>
/// 取消按钮事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void MyColorPicker_Canceled(object sender, EventArgs e)
{ {
ColorPanel.Visibility = Visibility.Collapsed; MyColorPickerClose(sender);
}
private void MyColorPicker_Confirmed(object sender, HandyControl.Data.FunctionEventArgs<Color> e)
{
MyColorPickerClose(sender);
} }
private void ColorPicker_SelectedColorChanged(object sender, HandyControl.Data.FunctionEventArgs<Color> e) private void MyColorPicker_SelectedColorChanged(object sender, HandyControl.Data.FunctionEventArgs<Color> e)
{ {
SolidColorBrush scb = ColorPicker.SelectedBrush; SolidColorBrush scb = MyColorPicker.SelectedBrush;
appConfig.TextColor = scb.ToString(); appConfig.TextColor = scb.ToString();
ColorPanel.Visibility = Visibility.Collapsed;
} }
/// <summary> /// <summary>
@@ -143,5 +157,27 @@ namespace GeekDesk.Control.UserControls.Config
} }
} }
} }
private void MyColorPicker_Checked(object sender, RoutedEventArgs e)
{
toggleButton = e.OriginalSource as System.Windows.Controls.Primitives.ToggleButton;
}
private void MyColorPickerClose(object sender)
{
if (toggleButton != null && toggleButton.IsChecked == true)
{
HandyControl.Controls.ColorPicker cp = sender as HandyControl.Controls.ColorPicker;
const BindingFlags InstanceBindFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
Type type = cp.GetType();
toggleButton.IsChecked = false;
MethodInfo mi = type.GetMethod("ToggleButtonDropper_Click", InstanceBindFlags);
mi.Invoke(cp, new object[] { null, null });
}
ColorPanel.Visibility = Visibility.Collapsed;
}
} }
} }