优化(
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));
|
||||
BoardBorderPenColorRed.Background = new SolidColorBrush(Color.FromRgb(239, 68, 68));
|
||||
BorderPenColorRed.Color = Color.FromRgb(239, 68, 68);
|
||||
BoardBorderPenColorRed.Color = Color.FromRgb(239, 68, 68);
|
||||
// 亮色的绿色
|
||||
BorderPenColorGreen.Background = new SolidColorBrush(Color.FromRgb(34, 197, 94));
|
||||
BoardBorderPenColorGreen.Background = new SolidColorBrush(Color.FromRgb(34, 197, 94));
|
||||
BorderPenColorGreen.Color = Color.FromRgb(34, 197, 94);
|
||||
BoardBorderPenColorGreen.Color = Color.FromRgb(34, 197, 94);
|
||||
// 亮色的蓝色
|
||||
BorderPenColorBlue.Background = new SolidColorBrush(Color.FromRgb(59, 130, 246));
|
||||
BoardBorderPenColorBlue.Background = new SolidColorBrush(Color.FromRgb(59, 130, 246));
|
||||
BorderPenColorBlue.Color = Color.FromRgb(59, 130, 246);
|
||||
BoardBorderPenColorBlue.Color = Color.FromRgb(59, 130, 246);
|
||||
// 亮色的黄色
|
||||
BorderPenColorYellow.Background = new SolidColorBrush(Color.FromRgb(250, 204, 21));
|
||||
BoardBorderPenColorYellow.Background = new SolidColorBrush(Color.FromRgb(250, 204, 21));
|
||||
BorderPenColorYellow.Color = Color.FromRgb(250, 204, 21);
|
||||
BoardBorderPenColorYellow.Color = Color.FromRgb(250, 204, 21);
|
||||
// 亮色的粉色
|
||||
BorderPenColorPink.Background = new SolidColorBrush(Color.FromRgb(236, 72, 153));
|
||||
BoardBorderPenColorPink.Background = new SolidColorBrush(Color.FromRgb(236, 72, 153));
|
||||
BorderPenColorPink.Color = Color.FromRgb(236, 72, 153);
|
||||
BoardBorderPenColorPink.Color = Color.FromRgb(236, 72, 153);
|
||||
// 亮色的Teal
|
||||
BorderPenColorTeal.Background = new SolidColorBrush(Color.FromRgb(20, 184, 166));
|
||||
BoardBorderPenColorTeal.Background = new SolidColorBrush(Color.FromRgb(20, 184, 166));
|
||||
BorderPenColorTeal.Color = Color.FromRgb(20, 184, 166);
|
||||
BoardBorderPenColorTeal.Color = Color.FromRgb(20, 184, 166);
|
||||
// 亮色的Orange
|
||||
BorderPenColorOrange.Background = new SolidColorBrush(Color.FromRgb(249, 115, 22));
|
||||
BoardBorderPenColorOrange.Background = new SolidColorBrush(Color.FromRgb(249, 115, 22));
|
||||
BorderPenColorOrange.Color = Color.FromRgb(249, 115, 22);
|
||||
BoardBorderPenColorOrange.Color = Color.FromRgb(249, 115, 22);
|
||||
|
||||
var newImageSource = new BitmapImage();
|
||||
newImageSource.BeginInit();
|
||||
@@ -319,26 +319,26 @@ namespace Ink_Canvas
|
||||
{
|
||||
// 暗系
|
||||
// 暗色的红色
|
||||
BorderPenColorRed.Background = new SolidColorBrush(Color.FromRgb(220, 38, 38));
|
||||
BoardBorderPenColorRed.Background = new SolidColorBrush(Color.FromRgb(220, 38, 38));
|
||||
BorderPenColorRed.Color = Color.FromRgb(220, 38, 38);
|
||||
BoardBorderPenColorRed.Color = Color.FromRgb(220, 38, 38);
|
||||
// 暗色的绿色
|
||||
BorderPenColorGreen.Background = new SolidColorBrush(Color.FromRgb(22, 163, 74));
|
||||
BoardBorderPenColorGreen.Background = new SolidColorBrush(Color.FromRgb(22, 163, 74));
|
||||
BorderPenColorGreen.Color = Color.FromRgb(22, 163, 74);
|
||||
BoardBorderPenColorGreen.Color = Color.FromRgb(22, 163, 74);
|
||||
// 暗色的蓝色
|
||||
BorderPenColorBlue.Background = new SolidColorBrush(Color.FromRgb(37, 99, 235));
|
||||
BoardBorderPenColorBlue.Background = new SolidColorBrush(Color.FromRgb(37, 99, 235));
|
||||
BorderPenColorBlue.Color = Color.FromRgb(37, 99, 235);
|
||||
BoardBorderPenColorBlue.Color = Color.FromRgb(37, 99, 235);
|
||||
// 暗色的黄色
|
||||
BorderPenColorYellow.Background = new SolidColorBrush(Color.FromRgb(234, 179, 8));
|
||||
BoardBorderPenColorYellow.Background = new SolidColorBrush(Color.FromRgb(234, 179, 8));
|
||||
BorderPenColorYellow.Color = Color.FromRgb(234, 179, 8);
|
||||
BoardBorderPenColorYellow.Color = Color.FromRgb(234, 179, 8);
|
||||
// 暗色的紫色对应亮色的粉色
|
||||
BorderPenColorPink.Background = new SolidColorBrush(Color.FromRgb(147, 51, 234));
|
||||
BoardBorderPenColorPink.Background = new SolidColorBrush(Color.FromRgb(147, 51, 234));
|
||||
BorderPenColorPink.Color = Color.FromRgb(147, 51, 234);
|
||||
BoardBorderPenColorPink.Color = Color.FromRgb(147, 51, 234);
|
||||
// 暗色的Teal
|
||||
BorderPenColorTeal.Background = new SolidColorBrush(Color.FromRgb(13, 148, 136));
|
||||
BoardBorderPenColorTeal.Background = new SolidColorBrush(Color.FromRgb(13, 148, 136));
|
||||
BorderPenColorTeal.Color = Color.FromRgb(13, 148, 136);
|
||||
BoardBorderPenColorTeal.Color = Color.FromRgb(13, 148, 136);
|
||||
// 暗色的Orange
|
||||
BorderPenColorOrange.Background = new SolidColorBrush(Color.FromRgb(234, 88, 12));
|
||||
BoardBorderPenColorOrange.Background = new SolidColorBrush(Color.FromRgb(234, 88, 12));
|
||||
BorderPenColorOrange.Color = Color.FromRgb(234, 88, 12);
|
||||
BoardBorderPenColorOrange.Color = Color.FromRgb(234, 88, 12);
|
||||
|
||||
var newImageSource = new BitmapImage();
|
||||
newImageSource.BeginInit();
|
||||
@@ -353,127 +353,129 @@ namespace Ink_Canvas
|
||||
}
|
||||
|
||||
// 改变选中提示
|
||||
ViewboxBtnColorBlackContent.Visibility = Visibility.Collapsed;
|
||||
ViewboxBtnColorBlueContent.Visibility = Visibility.Collapsed;
|
||||
ViewboxBtnColorGreenContent.Visibility = Visibility.Collapsed;
|
||||
ViewboxBtnColorRedContent.Visibility = Visibility.Collapsed;
|
||||
ViewboxBtnColorYellowContent.Visibility = Visibility.Collapsed;
|
||||
ViewboxBtnColorWhiteContent.Visibility = Visibility.Collapsed;
|
||||
ViewboxBtnColorPinkContent.Visibility = Visibility.Collapsed;
|
||||
ViewboxBtnColorTealContent.Visibility = Visibility.Collapsed;
|
||||
ViewboxBtnColorOrangeContent.Visibility = Visibility.Collapsed;
|
||||
BorderPenColorBlack.IsChecked = false;
|
||||
BorderPenColorBlue.IsChecked = false;
|
||||
BorderPenColorGreen.IsChecked = false;
|
||||
BorderPenColorRed.IsChecked = false;
|
||||
BorderPenColorYellow.IsChecked = false;
|
||||
BorderPenColorWhite.IsChecked = false;
|
||||
BorderPenColorPink.IsChecked = false;
|
||||
BorderPenColorTeal.IsChecked = false;
|
||||
BorderPenColorOrange.IsChecked = false;
|
||||
|
||||
BoardViewboxBtnColorBlackContent.Visibility = Visibility.Collapsed;
|
||||
BoardViewboxBtnColorBlueContent.Visibility = Visibility.Collapsed;
|
||||
BoardViewboxBtnColorGreenContent.Visibility = Visibility.Collapsed;
|
||||
BoardViewboxBtnColorRedContent.Visibility = Visibility.Collapsed;
|
||||
BoardViewboxBtnColorYellowContent.Visibility = Visibility.Collapsed;
|
||||
BoardViewboxBtnColorWhiteContent.Visibility = Visibility.Collapsed;
|
||||
BoardViewboxBtnColorPinkContent.Visibility = Visibility.Collapsed;
|
||||
BoardViewboxBtnColorTealContent.Visibility = Visibility.Collapsed;
|
||||
BoardViewboxBtnColorOrangeContent.Visibility = Visibility.Collapsed;
|
||||
BoardBorderPenColorBlack.IsChecked = false;
|
||||
BoardBorderPenColorBlue.IsChecked = false;
|
||||
BoardBorderPenColorGreen.IsChecked = false;
|
||||
BoardBorderPenColorRed.IsChecked = false;
|
||||
BoardBorderPenColorYellow.IsChecked = false;
|
||||
BoardBorderPenColorWhite.IsChecked = false;
|
||||
BoardBorderPenColorPink.IsChecked = false;
|
||||
BoardBorderPenColorTeal.IsChecked = false;
|
||||
BoardBorderPenColorOrange.IsChecked = false;
|
||||
|
||||
HighlighterPenViewboxBtnColorBlackContent.Visibility = Visibility.Collapsed;
|
||||
HighlighterPenViewboxBtnColorBlueContent.Visibility = Visibility.Collapsed;
|
||||
HighlighterPenViewboxBtnColorGreenContent.Visibility = Visibility.Collapsed;
|
||||
HighlighterPenViewboxBtnColorOrangeContent.Visibility = Visibility.Collapsed;
|
||||
HighlighterPenViewboxBtnColorPurpleContent.Visibility = Visibility.Collapsed;
|
||||
HighlighterPenViewboxBtnColorRedContent.Visibility = Visibility.Collapsed;
|
||||
HighlighterPenViewboxBtnColorTealContent.Visibility = Visibility.Collapsed;
|
||||
HighlighterPenViewboxBtnColorWhiteContent.Visibility = Visibility.Collapsed;
|
||||
HighlighterPenViewboxBtnColorYellowContent.Visibility = Visibility.Collapsed;
|
||||
HighlighterPenViewboxBtnColorZincContent.Visibility = Visibility.Collapsed;
|
||||
HighlighterPenColorBlack.IsChecked = false;
|
||||
HighlighterPenColorBlue.IsChecked = false;
|
||||
HighlighterPenColorGreen.IsChecked = false;
|
||||
HighlighterPenColorOrange.IsChecked = false;
|
||||
HighlighterPenPenColorPurple.IsChecked = false;
|
||||
HighlighterPenColorRed.IsChecked = false;
|
||||
HighlighterPenColorTeal.IsChecked = false;
|
||||
HighlighterPenColorWhite.IsChecked = false;
|
||||
HighlighterPenColorYellow.IsChecked = false;
|
||||
HighlighterPenColorZinc.IsChecked = false;
|
||||
|
||||
BoardHighlighterPenViewboxBtnColorBlackContent.Visibility = Visibility.Collapsed;
|
||||
BoardHighlighterPenViewboxBtnColorBlueContent.Visibility = Visibility.Collapsed;
|
||||
BoardHighlighterPenViewboxBtnColorGreenContent.Visibility = Visibility.Collapsed;
|
||||
BoardHighlighterPenViewboxBtnColorOrangeContent.Visibility = Visibility.Collapsed;
|
||||
BoardHighlighterPenViewboxBtnColorPurpleContent.Visibility = Visibility.Collapsed;
|
||||
BoardHighlighterPenViewboxBtnColorRedContent.Visibility = Visibility.Collapsed;
|
||||
BoardHighlighterPenViewboxBtnColorTealContent.Visibility = Visibility.Collapsed;
|
||||
BoardHighlighterPenViewboxBtnColorWhiteContent.Visibility = Visibility.Collapsed;
|
||||
BoardHighlighterPenViewboxBtnColorYellowContent.Visibility = Visibility.Collapsed;
|
||||
BoardHighlighterPenViewboxBtnColorZincContent.Visibility = Visibility.Collapsed;
|
||||
BoardHighlighterPenColorBlack.IsChecked = false;
|
||||
BoardHighlighterPenColorBlue.IsChecked = false;
|
||||
BoardHighlighterPenColorGreen.IsChecked = false;
|
||||
BoardHighlighterPenColorOrange.IsChecked = false;
|
||||
BoardHighlighterPenPenColorPurple.IsChecked = false;
|
||||
BoardHighlighterPenColorRed.IsChecked = false;
|
||||
BoardHighlighterPenColorTeal.IsChecked = false;
|
||||
BoardHighlighterPenColorWhite.IsChecked = false;
|
||||
BoardHighlighterPenColorYellow.IsChecked = false;
|
||||
BoardHighlighterPenColorZinc.IsChecked = false;
|
||||
|
||||
switch (inkColor)
|
||||
{
|
||||
case 0:
|
||||
ViewboxBtnColorBlackContent.Visibility = Visibility.Visible;
|
||||
BoardViewboxBtnColorBlackContent.Visibility = Visibility.Visible;
|
||||
BorderPenColorBlack.IsChecked = true;
|
||||
BoardBorderPenColorBlack.IsChecked = true;
|
||||
break;
|
||||
case 1:
|
||||
ViewboxBtnColorRedContent.Visibility = Visibility.Visible;
|
||||
BoardViewboxBtnColorRedContent.Visibility = Visibility.Visible;
|
||||
BorderPenColorRed.IsChecked = true;
|
||||
BoardBorderPenColorRed.IsChecked = true;
|
||||
break;
|
||||
case 2:
|
||||
ViewboxBtnColorGreenContent.Visibility = Visibility.Visible;
|
||||
BoardViewboxBtnColorGreenContent.Visibility = Visibility.Visible;
|
||||
BorderPenColorGreen.IsChecked = true;
|
||||
BoardBorderPenColorGreen.IsChecked = true;
|
||||
break;
|
||||
case 3:
|
||||
ViewboxBtnColorBlueContent.Visibility = Visibility.Visible;
|
||||
BoardViewboxBtnColorBlueContent.Visibility = Visibility.Visible;
|
||||
BorderPenColorBlue.IsChecked = true;
|
||||
BoardBorderPenColorBlue.IsChecked = true;
|
||||
break;
|
||||
case 4:
|
||||
ViewboxBtnColorYellowContent.Visibility = Visibility.Visible;
|
||||
BoardViewboxBtnColorYellowContent.Visibility = Visibility.Visible;
|
||||
BorderPenColorYellow.IsChecked = true;
|
||||
BoardBorderPenColorYellow.IsChecked = true;
|
||||
break;
|
||||
case 5:
|
||||
ViewboxBtnColorWhiteContent.Visibility = Visibility.Visible;
|
||||
BoardViewboxBtnColorWhiteContent.Visibility = Visibility.Visible;
|
||||
BorderPenColorWhite.IsChecked = true;
|
||||
BoardBorderPenColorWhite.IsChecked = true;
|
||||
break;
|
||||
case 6:
|
||||
ViewboxBtnColorPinkContent.Visibility = Visibility.Visible;
|
||||
BoardViewboxBtnColorPinkContent.Visibility = Visibility.Visible;
|
||||
BorderPenColorPink.IsChecked = true;
|
||||
BoardBorderPenColorPink.IsChecked = true;
|
||||
break;
|
||||
case 7:
|
||||
ViewboxBtnColorTealContent.Visibility = Visibility.Visible;
|
||||
BorderPenColorTeal.IsChecked = true;
|
||||
BoardBorderPenColorTeal.IsChecked = true;
|
||||
break;
|
||||
case 8:
|
||||
ViewboxBtnColorOrangeContent.Visibility = Visibility.Visible;
|
||||
BorderPenColorOrange.IsChecked = true;
|
||||
BoardBorderPenColorOrange.IsChecked = true;
|
||||
break;
|
||||
}
|
||||
|
||||
switch (highlighterColor)
|
||||
{
|
||||
case 100:
|
||||
HighlighterPenViewboxBtnColorBlackContent.Visibility = Visibility.Visible;
|
||||
BoardHighlighterPenViewboxBtnColorBlackContent.Visibility = Visibility.Visible;
|
||||
HighlighterPenColorBlack.IsChecked = true;
|
||||
BoardHighlighterPenColorBlack.IsChecked = true;
|
||||
break;
|
||||
case 101:
|
||||
HighlighterPenViewboxBtnColorWhiteContent.Visibility = Visibility.Visible;
|
||||
BoardHighlighterPenViewboxBtnColorWhiteContent.Visibility = Visibility.Visible;
|
||||
HighlighterPenColorWhite.IsChecked = true;
|
||||
BoardHighlighterPenColorWhite.IsChecked = true;
|
||||
break;
|
||||
case 102:
|
||||
HighlighterPenViewboxBtnColorRedContent.Visibility = Visibility.Visible;
|
||||
BoardHighlighterPenViewboxBtnColorRedContent.Visibility = Visibility.Visible;
|
||||
HighlighterPenColorRed.IsChecked = true;
|
||||
BoardHighlighterPenColorRed.IsChecked = true;
|
||||
break;
|
||||
case 103:
|
||||
HighlighterPenViewboxBtnColorYellowContent.Visibility = Visibility.Visible;
|
||||
BoardHighlighterPenViewboxBtnColorYellowContent.Visibility = Visibility.Visible;
|
||||
HighlighterPenColorYellow.IsChecked = true;
|
||||
BoardHighlighterPenColorYellow.IsChecked = true;
|
||||
break;
|
||||
case 104:
|
||||
HighlighterPenViewboxBtnColorGreenContent.Visibility = Visibility.Visible;
|
||||
BoardHighlighterPenViewboxBtnColorGreenContent.Visibility = Visibility.Visible;
|
||||
HighlighterPenColorGreen.IsChecked = true;
|
||||
BoardHighlighterPenColorGreen.IsChecked = true;
|
||||
break;
|
||||
case 105:
|
||||
HighlighterPenViewboxBtnColorZincContent.Visibility = Visibility.Visible;
|
||||
BoardHighlighterPenViewboxBtnColorZincContent.Visibility = Visibility.Visible;
|
||||
HighlighterPenColorZinc.IsChecked = true;
|
||||
BoardHighlighterPenColorZinc.IsChecked = true;
|
||||
break;
|
||||
case 106:
|
||||
HighlighterPenViewboxBtnColorBlueContent.Visibility = Visibility.Visible;
|
||||
BoardHighlighterPenViewboxBtnColorBlueContent.Visibility = Visibility.Visible;
|
||||
HighlighterPenColorBlue.IsChecked = true;
|
||||
BoardHighlighterPenColorBlue.IsChecked = true;
|
||||
break;
|
||||
case 107:
|
||||
HighlighterPenViewboxBtnColorPurpleContent.Visibility = Visibility.Visible;
|
||||
BoardHighlighterPenViewboxBtnColorPurpleContent.Visibility = Visibility.Visible;
|
||||
HighlighterPenPenColorPurple.IsChecked = true;
|
||||
BoardHighlighterPenPenColorPurple.IsChecked = true;
|
||||
break;
|
||||
case 108:
|
||||
HighlighterPenViewboxBtnColorTealContent.Visibility = Visibility.Visible;
|
||||
BoardHighlighterPenViewboxBtnColorTealContent.Visibility = Visibility.Visible;
|
||||
HighlighterPenColorTeal.IsChecked = true;
|
||||
BoardHighlighterPenColorTeal.IsChecked = true;
|
||||
break;
|
||||
case 109:
|
||||
HighlighterPenViewboxBtnColorOrangeContent.Visibility = Visibility.Visible;
|
||||
BoardHighlighterPenViewboxBtnColorOrangeContent.Visibility = Visibility.Visible;
|
||||
HighlighterPenColorOrange.IsChecked = true;
|
||||
BoardHighlighterPenColorOrange.IsChecked = true;
|
||||
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