124 lines
3.8 KiB
C#
124 lines
3.8 KiB
C#
using System;
|
|
using System.ComponentModel;
|
|
using System.Runtime.CompilerServices;
|
|
using System.Windows.Input;
|
|
using System.Windows.Media;
|
|
using StructureHelper.Annotations;
|
|
using StructureHelper.Infrastructure;
|
|
|
|
namespace StructureHelper
|
|
{
|
|
//public class ColorPickerViewModel : ViewModelBase
|
|
//{
|
|
// private int red, green, blue;
|
|
|
|
// public int Red
|
|
// {
|
|
// get => red;
|
|
// set => OnColorItemChanged(value, ref red);
|
|
// }
|
|
// public int Green
|
|
// {
|
|
// get => green;
|
|
// set => OnColorItemChanged(value, ref green);
|
|
// }
|
|
// public int Blue
|
|
// {
|
|
// get => blue;
|
|
// set => OnColorItemChanged(value, ref blue);
|
|
// }
|
|
|
|
// private SolidColorBrush selectedColor;
|
|
// public SolidColorBrush SelectedColor
|
|
// {
|
|
// get => selectedColor;
|
|
// set => OnPropertyChanged(value, selectedColor);
|
|
// }
|
|
// public ICommand SetColor { get; }
|
|
// public ColorPickerViewModel(PrimitiveDefinitionBase primitive)
|
|
// {
|
|
// if (primitive != null)
|
|
// {
|
|
// var solidBrush = primitive.Brush;
|
|
// Red = solidBrush.Color.R;
|
|
// Green = solidBrush.Color.G;
|
|
// Blue = solidBrush.Color.B;
|
|
|
|
// SetColor = new RelayCommand(o => primitive.Brush = SelectedColor);
|
|
// }
|
|
// }
|
|
// private void OnColorItemChanged(int value, ref int colorItem, [CallerMemberName] string propertyName = null)
|
|
// {
|
|
// if (value >= 0 && value <= 255 && Math.Abs(colorItem - value) > 0.001)
|
|
// {
|
|
// colorItem = value;
|
|
// OnPropertyChanged(propertyName);
|
|
// UpdateSelectedColor();
|
|
// }
|
|
// }
|
|
// private void UpdateSelectedColor()
|
|
// {
|
|
// var color = Color.FromRgb((byte)Red, (byte)Green, (byte)Blue);
|
|
// SelectedColor = new SolidColorBrush(color);
|
|
// OnPropertyChanged(nameof(SelectedColor));
|
|
// }
|
|
//}
|
|
|
|
public class ColorPickerViewModel : ViewModelBase
|
|
{
|
|
private int red, green, blue;
|
|
|
|
public int Red
|
|
{
|
|
get => red;
|
|
set => OnColorItemChanged(value, ref red);
|
|
}
|
|
public int Green
|
|
{
|
|
get => green;
|
|
set => OnColorItemChanged(value, ref green);
|
|
}
|
|
public int Blue
|
|
{
|
|
get => blue;
|
|
set => OnColorItemChanged(value, ref blue);
|
|
}
|
|
|
|
private SolidColorBrush selectedColor;
|
|
public SolidColorBrush SelectedColor
|
|
{
|
|
get => selectedColor;
|
|
//selectedColor = value;
|
|
set => OnPropertyChanged(value, ref selectedColor);
|
|
}
|
|
public ICommand SetColor { get; }
|
|
public ColorPickerViewModel(PrimitiveDefinitionBase primitive)
|
|
{
|
|
if (primitive != null)
|
|
{
|
|
var solidBrush = primitive.Brush;
|
|
Red = solidBrush.Color.R;
|
|
Green = solidBrush.Color.G;
|
|
Blue = solidBrush.Color.B;
|
|
|
|
SetColor = new RelayCommand(o => primitive.Brush = SelectedColor);
|
|
}
|
|
}
|
|
private void OnColorItemChanged(int value, ref int colorItem, [CallerMemberName] string propertyName = null)
|
|
{
|
|
if (value >= 0 && value <= 255 && Math.Abs(colorItem - value) > 0.001)
|
|
{
|
|
colorItem = value;
|
|
OnPropertyChanged(propertyName);
|
|
UpdateSelectedColor();
|
|
}
|
|
}
|
|
private void UpdateSelectedColor()
|
|
{
|
|
var color = Color.FromRgb((byte)Red, (byte)Green, (byte)Blue);
|
|
SelectedColor = new SolidColorBrush(color);
|
|
OnPropertyChanged(nameof(SelectedColor));
|
|
}
|
|
}
|
|
}
|