优化(
This commit is contained in:
+38
-1140
File diff suppressed because it is too large
Load Diff
@@ -283,26 +283,26 @@ namespace Ink_Canvas
|
|||||||
{
|
{
|
||||||
// 亮系
|
// 亮系
|
||||||
// 亮色的红色
|
// 亮色的红色
|
||||||
BorderPenColorRed.Background = new SolidColorBrush(Color.FromRgb(239, 68, 68));
|
BorderPenColorRed.Color = Color.FromRgb(239, 68, 68);
|
||||||
BoardBorderPenColorRed.Background = new SolidColorBrush(Color.FromRgb(239, 68, 68));
|
BoardBorderPenColorRed.Color = Color.FromRgb(239, 68, 68);
|
||||||
// 亮色的绿色
|
// 亮色的绿色
|
||||||
BorderPenColorGreen.Background = new SolidColorBrush(Color.FromRgb(34, 197, 94));
|
BorderPenColorGreen.Color = Color.FromRgb(34, 197, 94);
|
||||||
BoardBorderPenColorGreen.Background = new SolidColorBrush(Color.FromRgb(34, 197, 94));
|
BoardBorderPenColorGreen.Color = Color.FromRgb(34, 197, 94);
|
||||||
// 亮色的蓝色
|
// 亮色的蓝色
|
||||||
BorderPenColorBlue.Background = new SolidColorBrush(Color.FromRgb(59, 130, 246));
|
BorderPenColorBlue.Color = Color.FromRgb(59, 130, 246);
|
||||||
BoardBorderPenColorBlue.Background = new SolidColorBrush(Color.FromRgb(59, 130, 246));
|
BoardBorderPenColorBlue.Color = Color.FromRgb(59, 130, 246);
|
||||||
// 亮色的黄色
|
// 亮色的黄色
|
||||||
BorderPenColorYellow.Background = new SolidColorBrush(Color.FromRgb(250, 204, 21));
|
BorderPenColorYellow.Color = Color.FromRgb(250, 204, 21);
|
||||||
BoardBorderPenColorYellow.Background = new SolidColorBrush(Color.FromRgb(250, 204, 21));
|
BoardBorderPenColorYellow.Color = Color.FromRgb(250, 204, 21);
|
||||||
// 亮色的粉色
|
// 亮色的粉色
|
||||||
BorderPenColorPink.Background = new SolidColorBrush(Color.FromRgb(236, 72, 153));
|
BorderPenColorPink.Color = Color.FromRgb(236, 72, 153);
|
||||||
BoardBorderPenColorPink.Background = new SolidColorBrush(Color.FromRgb(236, 72, 153));
|
BoardBorderPenColorPink.Color = Color.FromRgb(236, 72, 153);
|
||||||
// 亮色的Teal
|
// 亮色的Teal
|
||||||
BorderPenColorTeal.Background = new SolidColorBrush(Color.FromRgb(20, 184, 166));
|
BorderPenColorTeal.Color = Color.FromRgb(20, 184, 166);
|
||||||
BoardBorderPenColorTeal.Background = new SolidColorBrush(Color.FromRgb(20, 184, 166));
|
BoardBorderPenColorTeal.Color = Color.FromRgb(20, 184, 166);
|
||||||
// 亮色的Orange
|
// 亮色的Orange
|
||||||
BorderPenColorOrange.Background = new SolidColorBrush(Color.FromRgb(249, 115, 22));
|
BorderPenColorOrange.Color = Color.FromRgb(249, 115, 22);
|
||||||
BoardBorderPenColorOrange.Background = new SolidColorBrush(Color.FromRgb(249, 115, 22));
|
BoardBorderPenColorOrange.Color = Color.FromRgb(249, 115, 22);
|
||||||
|
|
||||||
var newImageSource = new BitmapImage();
|
var newImageSource = new BitmapImage();
|
||||||
newImageSource.BeginInit();
|
newImageSource.BeginInit();
|
||||||
@@ -319,26 +319,26 @@ namespace Ink_Canvas
|
|||||||
{
|
{
|
||||||
// 暗系
|
// 暗系
|
||||||
// 暗色的红色
|
// 暗色的红色
|
||||||
BorderPenColorRed.Background = new SolidColorBrush(Color.FromRgb(220, 38, 38));
|
BorderPenColorRed.Color = Color.FromRgb(220, 38, 38);
|
||||||
BoardBorderPenColorRed.Background = new SolidColorBrush(Color.FromRgb(220, 38, 38));
|
BoardBorderPenColorRed.Color = Color.FromRgb(220, 38, 38);
|
||||||
// 暗色的绿色
|
// 暗色的绿色
|
||||||
BorderPenColorGreen.Background = new SolidColorBrush(Color.FromRgb(22, 163, 74));
|
BorderPenColorGreen.Color = Color.FromRgb(22, 163, 74);
|
||||||
BoardBorderPenColorGreen.Background = new SolidColorBrush(Color.FromRgb(22, 163, 74));
|
BoardBorderPenColorGreen.Color = Color.FromRgb(22, 163, 74);
|
||||||
// 暗色的蓝色
|
// 暗色的蓝色
|
||||||
BorderPenColorBlue.Background = new SolidColorBrush(Color.FromRgb(37, 99, 235));
|
BorderPenColorBlue.Color = Color.FromRgb(37, 99, 235);
|
||||||
BoardBorderPenColorBlue.Background = new SolidColorBrush(Color.FromRgb(37, 99, 235));
|
BoardBorderPenColorBlue.Color = Color.FromRgb(37, 99, 235);
|
||||||
// 暗色的黄色
|
// 暗色的黄色
|
||||||
BorderPenColorYellow.Background = new SolidColorBrush(Color.FromRgb(234, 179, 8));
|
BorderPenColorYellow.Color = Color.FromRgb(234, 179, 8);
|
||||||
BoardBorderPenColorYellow.Background = new SolidColorBrush(Color.FromRgb(234, 179, 8));
|
BoardBorderPenColorYellow.Color = Color.FromRgb(234, 179, 8);
|
||||||
// 暗色的紫色对应亮色的粉色
|
// 暗色的紫色对应亮色的粉色
|
||||||
BorderPenColorPink.Background = new SolidColorBrush(Color.FromRgb(147, 51, 234));
|
BorderPenColorPink.Color = Color.FromRgb(147, 51, 234);
|
||||||
BoardBorderPenColorPink.Background = new SolidColorBrush(Color.FromRgb(147, 51, 234));
|
BoardBorderPenColorPink.Color = Color.FromRgb(147, 51, 234);
|
||||||
// 暗色的Teal
|
// 暗色的Teal
|
||||||
BorderPenColorTeal.Background = new SolidColorBrush(Color.FromRgb(13, 148, 136));
|
BorderPenColorTeal.Color = Color.FromRgb(13, 148, 136);
|
||||||
BoardBorderPenColorTeal.Background = new SolidColorBrush(Color.FromRgb(13, 148, 136));
|
BoardBorderPenColorTeal.Color = Color.FromRgb(13, 148, 136);
|
||||||
// 暗色的Orange
|
// 暗色的Orange
|
||||||
BorderPenColorOrange.Background = new SolidColorBrush(Color.FromRgb(234, 88, 12));
|
BorderPenColorOrange.Color = Color.FromRgb(234, 88, 12);
|
||||||
BoardBorderPenColorOrange.Background = new SolidColorBrush(Color.FromRgb(234, 88, 12));
|
BoardBorderPenColorOrange.Color = Color.FromRgb(234, 88, 12);
|
||||||
|
|
||||||
var newImageSource = new BitmapImage();
|
var newImageSource = new BitmapImage();
|
||||||
newImageSource.BeginInit();
|
newImageSource.BeginInit();
|
||||||
@@ -353,127 +353,129 @@ namespace Ink_Canvas
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 改变选中提示
|
// 改变选中提示
|
||||||
ViewboxBtnColorBlackContent.Visibility = Visibility.Collapsed;
|
BorderPenColorBlack.IsChecked = false;
|
||||||
ViewboxBtnColorBlueContent.Visibility = Visibility.Collapsed;
|
BorderPenColorBlue.IsChecked = false;
|
||||||
ViewboxBtnColorGreenContent.Visibility = Visibility.Collapsed;
|
BorderPenColorGreen.IsChecked = false;
|
||||||
ViewboxBtnColorRedContent.Visibility = Visibility.Collapsed;
|
BorderPenColorRed.IsChecked = false;
|
||||||
ViewboxBtnColorYellowContent.Visibility = Visibility.Collapsed;
|
BorderPenColorYellow.IsChecked = false;
|
||||||
ViewboxBtnColorWhiteContent.Visibility = Visibility.Collapsed;
|
BorderPenColorWhite.IsChecked = false;
|
||||||
ViewboxBtnColorPinkContent.Visibility = Visibility.Collapsed;
|
BorderPenColorPink.IsChecked = false;
|
||||||
ViewboxBtnColorTealContent.Visibility = Visibility.Collapsed;
|
BorderPenColorTeal.IsChecked = false;
|
||||||
ViewboxBtnColorOrangeContent.Visibility = Visibility.Collapsed;
|
BorderPenColorOrange.IsChecked = false;
|
||||||
|
|
||||||
BoardViewboxBtnColorBlackContent.Visibility = Visibility.Collapsed;
|
BoardBorderPenColorBlack.IsChecked = false;
|
||||||
BoardViewboxBtnColorBlueContent.Visibility = Visibility.Collapsed;
|
BoardBorderPenColorBlue.IsChecked = false;
|
||||||
BoardViewboxBtnColorGreenContent.Visibility = Visibility.Collapsed;
|
BoardBorderPenColorGreen.IsChecked = false;
|
||||||
BoardViewboxBtnColorRedContent.Visibility = Visibility.Collapsed;
|
BoardBorderPenColorRed.IsChecked = false;
|
||||||
BoardViewboxBtnColorYellowContent.Visibility = Visibility.Collapsed;
|
BoardBorderPenColorYellow.IsChecked = false;
|
||||||
BoardViewboxBtnColorWhiteContent.Visibility = Visibility.Collapsed;
|
BoardBorderPenColorWhite.IsChecked = false;
|
||||||
BoardViewboxBtnColorPinkContent.Visibility = Visibility.Collapsed;
|
BoardBorderPenColorPink.IsChecked = false;
|
||||||
BoardViewboxBtnColorTealContent.Visibility = Visibility.Collapsed;
|
BoardBorderPenColorTeal.IsChecked = false;
|
||||||
BoardViewboxBtnColorOrangeContent.Visibility = Visibility.Collapsed;
|
BoardBorderPenColorOrange.IsChecked = false;
|
||||||
|
|
||||||
HighlighterPenViewboxBtnColorBlackContent.Visibility = Visibility.Collapsed;
|
HighlighterPenColorBlack.IsChecked = false;
|
||||||
HighlighterPenViewboxBtnColorBlueContent.Visibility = Visibility.Collapsed;
|
HighlighterPenColorBlue.IsChecked = false;
|
||||||
HighlighterPenViewboxBtnColorGreenContent.Visibility = Visibility.Collapsed;
|
HighlighterPenColorGreen.IsChecked = false;
|
||||||
HighlighterPenViewboxBtnColorOrangeContent.Visibility = Visibility.Collapsed;
|
HighlighterPenColorOrange.IsChecked = false;
|
||||||
HighlighterPenViewboxBtnColorPurpleContent.Visibility = Visibility.Collapsed;
|
HighlighterPenPenColorPurple.IsChecked = false;
|
||||||
HighlighterPenViewboxBtnColorRedContent.Visibility = Visibility.Collapsed;
|
HighlighterPenColorRed.IsChecked = false;
|
||||||
HighlighterPenViewboxBtnColorTealContent.Visibility = Visibility.Collapsed;
|
HighlighterPenColorTeal.IsChecked = false;
|
||||||
HighlighterPenViewboxBtnColorWhiteContent.Visibility = Visibility.Collapsed;
|
HighlighterPenColorWhite.IsChecked = false;
|
||||||
HighlighterPenViewboxBtnColorYellowContent.Visibility = Visibility.Collapsed;
|
HighlighterPenColorYellow.IsChecked = false;
|
||||||
HighlighterPenViewboxBtnColorZincContent.Visibility = Visibility.Collapsed;
|
HighlighterPenColorZinc.IsChecked = false;
|
||||||
|
|
||||||
BoardHighlighterPenViewboxBtnColorBlackContent.Visibility = Visibility.Collapsed;
|
BoardHighlighterPenColorBlack.IsChecked = false;
|
||||||
BoardHighlighterPenViewboxBtnColorBlueContent.Visibility = Visibility.Collapsed;
|
BoardHighlighterPenColorBlue.IsChecked = false;
|
||||||
BoardHighlighterPenViewboxBtnColorGreenContent.Visibility = Visibility.Collapsed;
|
BoardHighlighterPenColorGreen.IsChecked = false;
|
||||||
BoardHighlighterPenViewboxBtnColorOrangeContent.Visibility = Visibility.Collapsed;
|
BoardHighlighterPenColorOrange.IsChecked = false;
|
||||||
BoardHighlighterPenViewboxBtnColorPurpleContent.Visibility = Visibility.Collapsed;
|
BoardHighlighterPenPenColorPurple.IsChecked = false;
|
||||||
BoardHighlighterPenViewboxBtnColorRedContent.Visibility = Visibility.Collapsed;
|
BoardHighlighterPenColorRed.IsChecked = false;
|
||||||
BoardHighlighterPenViewboxBtnColorTealContent.Visibility = Visibility.Collapsed;
|
BoardHighlighterPenColorTeal.IsChecked = false;
|
||||||
BoardHighlighterPenViewboxBtnColorWhiteContent.Visibility = Visibility.Collapsed;
|
BoardHighlighterPenColorWhite.IsChecked = false;
|
||||||
BoardHighlighterPenViewboxBtnColorYellowContent.Visibility = Visibility.Collapsed;
|
BoardHighlighterPenColorYellow.IsChecked = false;
|
||||||
BoardHighlighterPenViewboxBtnColorZincContent.Visibility = Visibility.Collapsed;
|
BoardHighlighterPenColorZinc.IsChecked = false;
|
||||||
|
|
||||||
switch (inkColor)
|
switch (inkColor)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
ViewboxBtnColorBlackContent.Visibility = Visibility.Visible;
|
BorderPenColorBlack.IsChecked = true;
|
||||||
BoardViewboxBtnColorBlackContent.Visibility = Visibility.Visible;
|
BoardBorderPenColorBlack.IsChecked = true;
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
ViewboxBtnColorRedContent.Visibility = Visibility.Visible;
|
BorderPenColorRed.IsChecked = true;
|
||||||
BoardViewboxBtnColorRedContent.Visibility = Visibility.Visible;
|
BoardBorderPenColorRed.IsChecked = true;
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
ViewboxBtnColorGreenContent.Visibility = Visibility.Visible;
|
BorderPenColorGreen.IsChecked = true;
|
||||||
BoardViewboxBtnColorGreenContent.Visibility = Visibility.Visible;
|
BoardBorderPenColorGreen.IsChecked = true;
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
ViewboxBtnColorBlueContent.Visibility = Visibility.Visible;
|
BorderPenColorBlue.IsChecked = true;
|
||||||
BoardViewboxBtnColorBlueContent.Visibility = Visibility.Visible;
|
BoardBorderPenColorBlue.IsChecked = true;
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
ViewboxBtnColorYellowContent.Visibility = Visibility.Visible;
|
BorderPenColorYellow.IsChecked = true;
|
||||||
BoardViewboxBtnColorYellowContent.Visibility = Visibility.Visible;
|
BoardBorderPenColorYellow.IsChecked = true;
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
ViewboxBtnColorWhiteContent.Visibility = Visibility.Visible;
|
BorderPenColorWhite.IsChecked = true;
|
||||||
BoardViewboxBtnColorWhiteContent.Visibility = Visibility.Visible;
|
BoardBorderPenColorWhite.IsChecked = true;
|
||||||
break;
|
break;
|
||||||
case 6:
|
case 6:
|
||||||
ViewboxBtnColorPinkContent.Visibility = Visibility.Visible;
|
BorderPenColorPink.IsChecked = true;
|
||||||
BoardViewboxBtnColorPinkContent.Visibility = Visibility.Visible;
|
BoardBorderPenColorPink.IsChecked = true;
|
||||||
break;
|
break;
|
||||||
case 7:
|
case 7:
|
||||||
ViewboxBtnColorTealContent.Visibility = Visibility.Visible;
|
BorderPenColorTeal.IsChecked = true;
|
||||||
|
BoardBorderPenColorTeal.IsChecked = true;
|
||||||
break;
|
break;
|
||||||
case 8:
|
case 8:
|
||||||
ViewboxBtnColorOrangeContent.Visibility = Visibility.Visible;
|
BorderPenColorOrange.IsChecked = true;
|
||||||
|
BoardBorderPenColorOrange.IsChecked = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (highlighterColor)
|
switch (highlighterColor)
|
||||||
{
|
{
|
||||||
case 100:
|
case 100:
|
||||||
HighlighterPenViewboxBtnColorBlackContent.Visibility = Visibility.Visible;
|
HighlighterPenColorBlack.IsChecked = true;
|
||||||
BoardHighlighterPenViewboxBtnColorBlackContent.Visibility = Visibility.Visible;
|
BoardHighlighterPenColorBlack.IsChecked = true;
|
||||||
break;
|
break;
|
||||||
case 101:
|
case 101:
|
||||||
HighlighterPenViewboxBtnColorWhiteContent.Visibility = Visibility.Visible;
|
HighlighterPenColorWhite.IsChecked = true;
|
||||||
BoardHighlighterPenViewboxBtnColorWhiteContent.Visibility = Visibility.Visible;
|
BoardHighlighterPenColorWhite.IsChecked = true;
|
||||||
break;
|
break;
|
||||||
case 102:
|
case 102:
|
||||||
HighlighterPenViewboxBtnColorRedContent.Visibility = Visibility.Visible;
|
HighlighterPenColorRed.IsChecked = true;
|
||||||
BoardHighlighterPenViewboxBtnColorRedContent.Visibility = Visibility.Visible;
|
BoardHighlighterPenColorRed.IsChecked = true;
|
||||||
break;
|
break;
|
||||||
case 103:
|
case 103:
|
||||||
HighlighterPenViewboxBtnColorYellowContent.Visibility = Visibility.Visible;
|
HighlighterPenColorYellow.IsChecked = true;
|
||||||
BoardHighlighterPenViewboxBtnColorYellowContent.Visibility = Visibility.Visible;
|
BoardHighlighterPenColorYellow.IsChecked = true;
|
||||||
break;
|
break;
|
||||||
case 104:
|
case 104:
|
||||||
HighlighterPenViewboxBtnColorGreenContent.Visibility = Visibility.Visible;
|
HighlighterPenColorGreen.IsChecked = true;
|
||||||
BoardHighlighterPenViewboxBtnColorGreenContent.Visibility = Visibility.Visible;
|
BoardHighlighterPenColorGreen.IsChecked = true;
|
||||||
break;
|
break;
|
||||||
case 105:
|
case 105:
|
||||||
HighlighterPenViewboxBtnColorZincContent.Visibility = Visibility.Visible;
|
HighlighterPenColorZinc.IsChecked = true;
|
||||||
BoardHighlighterPenViewboxBtnColorZincContent.Visibility = Visibility.Visible;
|
BoardHighlighterPenColorZinc.IsChecked = true;
|
||||||
break;
|
break;
|
||||||
case 106:
|
case 106:
|
||||||
HighlighterPenViewboxBtnColorBlueContent.Visibility = Visibility.Visible;
|
HighlighterPenColorBlue.IsChecked = true;
|
||||||
BoardHighlighterPenViewboxBtnColorBlueContent.Visibility = Visibility.Visible;
|
BoardHighlighterPenColorBlue.IsChecked = true;
|
||||||
break;
|
break;
|
||||||
case 107:
|
case 107:
|
||||||
HighlighterPenViewboxBtnColorPurpleContent.Visibility = Visibility.Visible;
|
HighlighterPenPenColorPurple.IsChecked = true;
|
||||||
BoardHighlighterPenViewboxBtnColorPurpleContent.Visibility = Visibility.Visible;
|
BoardHighlighterPenPenColorPurple.IsChecked = true;
|
||||||
break;
|
break;
|
||||||
case 108:
|
case 108:
|
||||||
HighlighterPenViewboxBtnColorTealContent.Visibility = Visibility.Visible;
|
HighlighterPenColorTeal.IsChecked = true;
|
||||||
BoardHighlighterPenViewboxBtnColorTealContent.Visibility = Visibility.Visible;
|
BoardHighlighterPenColorTeal.IsChecked = true;
|
||||||
break;
|
break;
|
||||||
case 109:
|
case 109:
|
||||||
HighlighterPenViewboxBtnColorOrangeContent.Visibility = Visibility.Visible;
|
HighlighterPenColorOrange.IsChecked = true;
|
||||||
BoardHighlighterPenViewboxBtnColorOrangeContent.Visibility = Visibility.Visible;
|
BoardHighlighterPenColorOrange.IsChecked = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
<UserControl x:Class="Ink_Canvas.Controls.PenColorButton"
|
||||||
|
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"
|
||||||
|
mc:Ignorable="d"
|
||||||
|
d:DesignHeight="45" d:DesignWidth="45">
|
||||||
|
<Border x:Name="ButtonBorder"
|
||||||
|
BorderThickness="1.5"
|
||||||
|
CornerRadius="100"
|
||||||
|
Width="45" Height="45"
|
||||||
|
MouseUp="ButtonBorder_MouseUp">
|
||||||
|
<Canvas x:Name="RootCanvas">
|
||||||
|
<Image x:Name="TransparentGridImage"
|
||||||
|
Source="/Resources/Icons-png/transparent-grid.png"
|
||||||
|
Width="42" Height="42"
|
||||||
|
Visibility="Collapsed">
|
||||||
|
<Image.Clip>
|
||||||
|
<EllipseGeometry x:Name="ClipGeometry"
|
||||||
|
Center="21,21"
|
||||||
|
RadiusX="21"
|
||||||
|
RadiusY="21" />
|
||||||
|
</Image.Clip>
|
||||||
|
</Image>
|
||||||
|
<Border x:Name="ColorBorder"
|
||||||
|
Width="42" Height="42"
|
||||||
|
CornerRadius="21"
|
||||||
|
Opacity="1" />
|
||||||
|
<Viewbox x:Name="CheckViewbox"
|
||||||
|
Visibility="Collapsed"
|
||||||
|
Margin="8"
|
||||||
|
Canvas.Top="0"
|
||||||
|
Canvas.Left="0">
|
||||||
|
<Image x:Name="CheckImage"
|
||||||
|
RenderOptions.BitmapScalingMode="HighQuality"
|
||||||
|
VerticalAlignment="Top"
|
||||||
|
Width="24" Height="24" />
|
||||||
|
</Viewbox>
|
||||||
|
</Canvas>
|
||||||
|
</Border>
|
||||||
|
</UserControl>
|
||||||
@@ -0,0 +1,141 @@
|
|||||||
|
using System.Windows;
|
||||||
|
using System.Windows.Controls;
|
||||||
|
using System.Windows.Input;
|
||||||
|
using System.Windows.Media;
|
||||||
|
|
||||||
|
namespace Ink_Canvas.Controls
|
||||||
|
{
|
||||||
|
public partial class PenColorButton : UserControl
|
||||||
|
{
|
||||||
|
public static readonly DependencyProperty ColorProperty = DependencyProperty.Register(
|
||||||
|
nameof(Color), typeof(Color), typeof(PenColorButton),
|
||||||
|
new PropertyMetadata(Colors.Black, OnColorChanged));
|
||||||
|
|
||||||
|
private static void OnColorChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||||
|
{
|
||||||
|
var button = (PenColorButton)d;
|
||||||
|
if (button.ColorBorder != null)
|
||||||
|
{
|
||||||
|
button.ColorBorder.Background = new SolidColorBrush((Color)e.NewValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Color Color
|
||||||
|
{
|
||||||
|
get => (Color)GetValue(ColorProperty);
|
||||||
|
set => SetValue(ColorProperty, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static readonly DependencyProperty BorderBrushColorProperty = DependencyProperty.Register(
|
||||||
|
nameof(BorderBrushColor), typeof(Color), typeof(PenColorButton),
|
||||||
|
new PropertyMetadata(Colors.Gray, OnBorderBrushColorChanged));
|
||||||
|
|
||||||
|
private static void OnBorderBrushColorChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||||
|
{
|
||||||
|
var button = (PenColorButton)d;
|
||||||
|
if (button.ButtonBorder != null)
|
||||||
|
{
|
||||||
|
button.ButtonBorder.BorderBrush = new SolidColorBrush((Color)e.NewValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Color BorderBrushColor
|
||||||
|
{
|
||||||
|
get => (Color)GetValue(BorderBrushColorProperty);
|
||||||
|
set => SetValue(BorderBrushColorProperty, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static readonly DependencyProperty IsHighlighterProperty = DependencyProperty.Register(
|
||||||
|
nameof(IsHighlighter), typeof(bool), typeof(PenColorButton),
|
||||||
|
new PropertyMetadata(false, OnIsHighlighterChanged));
|
||||||
|
|
||||||
|
private static void OnIsHighlighterChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||||
|
{
|
||||||
|
var button = (PenColorButton)d;
|
||||||
|
if (button.TransparentGridImage != null && button.ColorBorder != null)
|
||||||
|
{
|
||||||
|
bool isHighlighter = (bool)e.NewValue;
|
||||||
|
button.TransparentGridImage.Visibility = isHighlighter ? Visibility.Visible : Visibility.Collapsed;
|
||||||
|
button.ColorBorder.Opacity = isHighlighter ? 0.75 : 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsHighlighter
|
||||||
|
{
|
||||||
|
get => (bool)GetValue(IsHighlighterProperty);
|
||||||
|
set => SetValue(IsHighlighterProperty, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static readonly DependencyProperty IsCheckedProperty = DependencyProperty.Register(
|
||||||
|
nameof(IsChecked), typeof(bool), typeof(PenColorButton),
|
||||||
|
new PropertyMetadata(false, OnIsCheckedChanged));
|
||||||
|
|
||||||
|
private static void OnIsCheckedChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||||
|
{
|
||||||
|
var button = (PenColorButton)d;
|
||||||
|
if (button.CheckViewbox != null)
|
||||||
|
{
|
||||||
|
button.CheckViewbox.Visibility = (bool)e.NewValue ? Visibility.Visible : Visibility.Collapsed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsChecked
|
||||||
|
{
|
||||||
|
get => (bool)GetValue(IsCheckedProperty);
|
||||||
|
set => SetValue(IsCheckedProperty, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static readonly DependencyProperty CheckIconSourceProperty = DependencyProperty.Register(
|
||||||
|
nameof(CheckIconSource), typeof(string), typeof(PenColorButton),
|
||||||
|
new PropertyMetadata("/Resources/new-icons/checked-white.png", OnCheckIconSourceChanged));
|
||||||
|
|
||||||
|
private static void OnCheckIconSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||||
|
{
|
||||||
|
var button = (PenColorButton)d;
|
||||||
|
if (button.CheckImage != null && e.NewValue is string source)
|
||||||
|
{
|
||||||
|
button.CheckImage.Source = new System.Windows.Media.Imaging.BitmapImage(new System.Uri(source, System.UriKind.Relative));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string CheckIconSource
|
||||||
|
{
|
||||||
|
get => (string)GetValue(CheckIconSourceProperty);
|
||||||
|
set => SetValue(CheckIconSourceProperty, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public event MouseButtonEventHandler ButtonMouseUp;
|
||||||
|
|
||||||
|
public PenColorButton()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
Loaded += PenColorButton_Loaded;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void PenColorButton_Loaded(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
ApplyProperties();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ApplyProperties()
|
||||||
|
{
|
||||||
|
if (ColorBorder != null)
|
||||||
|
ColorBorder.Background = new SolidColorBrush(Color);
|
||||||
|
if (ButtonBorder != null)
|
||||||
|
ButtonBorder.BorderBrush = new SolidColorBrush(BorderBrushColor);
|
||||||
|
if (TransparentGridImage != null)
|
||||||
|
TransparentGridImage.Visibility = IsHighlighter ? Visibility.Visible : Visibility.Collapsed;
|
||||||
|
if (ColorBorder != null)
|
||||||
|
ColorBorder.Opacity = IsHighlighter ? 0.75 : 1;
|
||||||
|
if (CheckViewbox != null)
|
||||||
|
CheckViewbox.Visibility = IsChecked ? Visibility.Visible : Visibility.Collapsed;
|
||||||
|
if (CheckImage != null && !string.IsNullOrEmpty(CheckIconSource))
|
||||||
|
CheckImage.Source = new System.Windows.Media.Imaging.BitmapImage(new System.Uri(CheckIconSource, System.UriKind.Relative));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonBorder_MouseUp(object sender, MouseButtonEventArgs e)
|
||||||
|
{
|
||||||
|
ButtonMouseUp?.Invoke(this, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user