From 9030ede0459418011195e639559509f68462b47a Mon Sep 17 00:00:00 2001
From: Roberto T <61755417+RobertGlobant20@users.noreply.github.com>
Date: Mon, 6 Mar 2023 14:34:02 -0600
Subject: [PATCH] Dyn 4738 custom color picker (#13794)
* DYN-4738-Custom-ColorPicker
First version of the customized ColorPicker so it can be used in GroupStyles and in Color Palette node.
* DYN-4738-Custom-ColorPicker
CustomColorPicker fixed to use only the Basic Colors and hide the Custom Colors.
First changes for integrating color picker in Color Palette node.
* DYN-4738-Custom-ColorPicker
Adapting the CustomColorPicker to be used in the Color Palette node.
* DYN-4738-Custom-ColorPicker
Refactoring some code and adding comments.
* DYN-4738-Custom-ColorPicker Code Review1
Adding comments
* DYN-4738-Custom-ColorPicker Code Review2
Reverting code added for debugging.
---
src/DynamoCoreWpf/DynamoCoreWpf.csproj | 12 +
src/DynamoCoreWpf/UI/Converters.cs | 56 +++++
.../UI/Themes/Modern/DynamoConverters.xaml | 2 +
.../UI/Themes/Modern/DynamoModern.xaml | 131 ++++++++++
.../Core/CustomColorPickerViewModel.cs | 227 ++++++++++++++++++
.../Views/Core/CustomColorPicker.xaml | 220 +++++++++++++++++
.../Views/Core/CustomColorPicker.xaml.cs | 62 +++++
.../Views/Menu/PreferencesView.xaml.cs | 27 ++-
.../ColorPaletteViewModel.cs | 26 ++
.../Controls/ColorPalette.xaml | 72 ++++--
.../Controls/ColorPalette.xaml.cs | 53 +++-
.../CoreNodeModelsWpf.csproj | 5 -
.../NodeViewCustomizations/ColorPalette.cs | 26 +-
13 files changed, 881 insertions(+), 38 deletions(-)
create mode 100644 src/DynamoCoreWpf/ViewModels/Core/CustomColorPickerViewModel.cs
create mode 100644 src/DynamoCoreWpf/Views/Core/CustomColorPicker.xaml
create mode 100644 src/DynamoCoreWpf/Views/Core/CustomColorPicker.xaml.cs
create mode 100644 src/Libraries/CoreNodeModelsWpf/ColorPaletteViewModel.cs
diff --git a/src/DynamoCoreWpf/DynamoCoreWpf.csproj b/src/DynamoCoreWpf/DynamoCoreWpf.csproj
index cb702bceb57..9daeded0b99 100644
--- a/src/DynamoCoreWpf/DynamoCoreWpf.csproj
+++ b/src/DynamoCoreWpf/DynamoCoreWpf.csproj
@@ -48,6 +48,7 @@
+
@@ -143,6 +144,11 @@
+
+ true
+
+ runtime
+
@@ -337,6 +343,7 @@
+
@@ -385,6 +392,7 @@
ConnectorContextMenuView.xaml
+
ConnectorPinView.xaml
@@ -553,6 +561,10 @@
Designer
MSBuild:Compile
+
+
+ MSBuild:Compile
+
MSBuild:Compile
diff --git a/src/DynamoCoreWpf/UI/Converters.cs b/src/DynamoCoreWpf/UI/Converters.cs
index a3fd3df54c7..50387a02f5d 100644
--- a/src/DynamoCoreWpf/UI/Converters.cs
+++ b/src/DynamoCoreWpf/UI/Converters.cs
@@ -3641,4 +3641,60 @@ private double GetRelativeLuminance(System.Windows.Media.Color color)
return 0.2126 * R + 0.7152 * G + 0.0722 * B;
}
}
+
+ ///
+ /// This converter is used to add extra space between the ListBox and the CustomColorPicker border
+ ///
+ public class AdditionConverter : IValueConverter
+ {
+ public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
+ {
+ if ((value != null) && (parameter != null))
+ {
+ var firstValue = System.Convert.ToDouble(value);
+ var secondValue = double.Parse(parameter as string);
+
+ return firstValue + secondValue;
+ }
+
+ return 0d;
+ }
+
+ public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
+ {
+ throw new NotImplementedException();
+ }
+ }
+
+ public class ColorToSolidColorBrushConverter : IValueConverter
+ {
+ ///
+ /// Converts a Color to a SolidColorBrush.
+ ///
+ ///
+ /// A converted SolidColorBrush. If the method returns null, the valid null value is used.
+ ///
+ public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
+ {
+ if (value != null)
+ return new SolidColorBrush((Color)value);
+
+ return value;
+ }
+
+
+ ///
+ /// Converts a SolidColorBrush to a Color.
+ ///
+ ///
+ /// A converted value. If the method returns null, the valid null value is used.
+ ///
+ public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
+ {
+ if (value != null)
+ return ((SolidColorBrush)value).Color;
+
+ return value;
+ }
+ }
}
diff --git a/src/DynamoCoreWpf/UI/Themes/Modern/DynamoConverters.xaml b/src/DynamoCoreWpf/UI/Themes/Modern/DynamoConverters.xaml
index c292360073a..e4969da7f0e 100644
--- a/src/DynamoCoreWpf/UI/Themes/Modern/DynamoConverters.xaml
+++ b/src/DynamoCoreWpf/UI/Themes/Modern/DynamoConverters.xaml
@@ -187,4 +187,6 @@
+
+
diff --git a/src/DynamoCoreWpf/UI/Themes/Modern/DynamoModern.xaml b/src/DynamoCoreWpf/UI/Themes/Modern/DynamoModern.xaml
index 2fee1a9066f..9447bee63b4 100644
--- a/src/DynamoCoreWpf/UI/Themes/Modern/DynamoModern.xaml
+++ b/src/DynamoCoreWpf/UI/Themes/Modern/DynamoModern.xaml
@@ -6,6 +6,8 @@
xmlns:nodes="clr-namespace:Dynamo.Nodes;assembly=DynamoCoreWpf"
xmlns:dynui="clr-namespace:Dynamo.UI.Controls;assembly=DynamoCoreWpf"
xmlns:fa="clr-namespace:FontAwesome.WPF;assembly=FontAwesome.WPF"
+ xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
+ xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:p="clr-namespace:Dynamo.Wpf.Properties;assembly=DynamoCoreWpf"
xmlns:ui="clr-namespace:Dynamo.UI;assembly=DynamoCoreWpf">
@@ -5668,4 +5670,133 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/DynamoCoreWpf/ViewModels/Core/CustomColorPickerViewModel.cs b/src/DynamoCoreWpf/ViewModels/Core/CustomColorPickerViewModel.cs
new file mode 100644
index 00000000000..c23f0f485b2
--- /dev/null
+++ b/src/DynamoCoreWpf/ViewModels/Core/CustomColorPickerViewModel.cs
@@ -0,0 +1,227 @@
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.ComponentModel;
+using System.Runtime.CompilerServices;
+using System.Windows.Media;
+using Dynamo.Core;
+using Xceed.Wpf.Toolkit;
+
+namespace Dynamo.ViewModels
+{
+ internal class CustomColorItem : ColorItem, INotifyPropertyChanged
+ {
+ ///
+ /// This event will help to execute the method OnPropertyChanged used for xaml bindings (NotificationObject class cannot be used due that we already derive from ColorItem)
+ ///
+ public event PropertyChangedEventHandler PropertyChanged;
+
+ private bool isColorItemSelected = false;
+ public bool IsColorItemSelected
+ {
+ get
+ {
+ return isColorItemSelected;
+ }
+ set
+ {
+ isColorItemSelected = value;
+ OnPropertyChanged(nameof(IsColorItemSelected));
+ }
+ }
+
+ ///
+ /// Constructor that initialize the base class with the values passed as paramters
+ ///
+ /// color that will be displayed in the ColorPicker list
+ /// description or color name that will be displayed as tooltip when mouse hover a specific color
+ public CustomColorItem(Color? color, string name) : base(color, name)
+ {
+
+ }
+
+ // Create the OnPropertyChanged method to raise the event
+ // The calling member's name will be used as the parameter.
+ protected void OnPropertyChanged([CallerMemberName] string name = null)
+ {
+ PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
+ }
+ }
+
+ internal class CustomColorPickerViewModel : NotificationObject
+ {
+ private Color? colorPickerFinalSelectedColor;
+ private ObservableCollection basicColors;
+ private ObservableCollection customColors;
+
+
+ ///
+ /// Color Selected in the ColorPicker
+ ///
+ public Color? ColorPickerFinalSelectedColor
+ {
+ get
+ {
+ return colorPickerFinalSelectedColor;
+ }
+ set
+ {
+ colorPickerFinalSelectedColor = value;
+ RaisePropertyChanged(nameof(ColorPickerFinalSelectedColor));
+ }
+ }
+
+ ///
+ /// List of Basic Colors that will be displayed in the CustomColorPicker
+ ///
+ public ObservableCollection BasicColors
+ {
+ get
+ {
+ return basicColors;
+ }
+ set
+ {
+ basicColors = value;
+ RaisePropertyChanged(nameof(BasicColors));
+ }
+ }
+
+ ///
+ /// List of Custom Colors that will be displayed in the CustomColorPicker
+ ///
+ public ObservableCollection CustomColors
+ {
+ get
+ {
+ return customColors;
+ }
+ set
+ {
+ customColors = value;
+ RaisePropertyChanged(nameof(CustomColors));
+ }
+ }
+
+ public CustomColorPickerViewModel()
+ {
+ BasicColors = new ObservableCollection();
+ BasicColors = CreateBasicColorsCollection();
+
+ CustomColors = new ObservableCollection();
+ CustomColors = CreateCustomColorsCollection();
+ }
+
+ private static ObservableCollection CreateBasicColorsCollection()
+ {
+ //This list of colors were taken from the design created by the UX team in the Jira task (based from the Weave component).
+ //Also you can find more details of the colors used in the next link: https://weave.autodesk.com/web/basics/colors-data-viz
+ ObservableCollection observableCollection = new ObservableCollection();
+
+ List<(int R, int G, int B)> colors = new List<(int, int, int)>()
+ {
+ (77, 0, 0),
+ (77, 19, 0),
+ (77, 38, 0),
+ (77, 58, 0),
+ (77, 77, 1),
+ (58, 76, 2),
+ (37, 76, 2),
+ (19, 77, 1),
+ (0, 77, 1),
+ (0, 77, 20),
+ (0, 77, 38),
+ (0, 77, 57),
+ (0, 76, 76),
+ (0, 58, 76),
+ (0, 39, 76),
+ (0, 21, 76),
+ (129, 0, 1),
+ (129, 31, 1),
+ (129, 63, 0),
+ (128, 95, 1),
+ (128, 127, 5),
+ (95, 127, 4),
+ (63, 126, 3),
+ (30, 127, 2),
+ (0, 127, 2),
+ (0, 127, 32),
+ (0, 128, 63),
+ (0, 127, 95),
+ (0, 127, 127),
+ (0, 95, 127),
+ (0, 64, 127),
+ (0, 32, 127),
+ (155, 0, 2),
+ (155, 38, 2),
+ (155, 76, 3),
+ (154, 114, 3),
+ (154, 153, 3),
+ (114, 153, 5),
+ (77, 153, 3),
+ (35, 153, 3),
+ (0, 153, 4),
+ (0, 153, 38),
+ (0, 153, 76),
+ (0, 154, 113),
+ (0, 153, 153),
+ (0, 114, 153),
+ (0, 78, 153),
+ (0, 39, 153),
+ (206, 1, 1),
+ (206, 51, 3),
+ (206, 101, 4),
+ (206, 153, 3),
+ (205, 204, 0),
+ (153, 205, 6),
+ (100, 205, 7),
+ (46, 204, 3),
+ (0, 204, 5),
+ (0, 204, 51),
+ (0, 204, 102),
+ (0, 204, 153),
+ (0, 204, 204),
+ (0, 154, 204),
+ (0, 102, 204),
+ (0, 53, 204),
+ (255, 0, 0),
+ (255, 64, 0),
+ (255, 127, 1),
+ (255, 192, 0),
+ (255, 255, 0),
+ (190, 254, 5),
+ (125, 255, 2),
+ (59, 254, 5),
+ (0, 254, 1),
+ (0, 254, 63),
+ (0, 255, 127),
+ (0, 255, 191),
+ (0, 255, 255),
+ (0, 192, 255),
+ (0, 128, 254),
+ (0, 67, 255)
+ };
+
+
+ foreach (var color in colors)
+ {
+ var colorItem = Color.FromRgb((byte)color.R, (byte)color.G, (byte)color.B);
+ observableCollection.Add(new CustomColorItem(colorItem, string.Format("#{0},{1},{2}", color.R, color.G, color.B)));
+ }
+
+ return observableCollection;
+ }
+
+ ///
+ /// Creates de default List of Custom Colors (this will be modified by the user
+ ///
+ ///
+ private static ObservableCollection CreateCustomColorsCollection()
+ {
+ ObservableCollection observableCollection = new ObservableCollection();
+ var colorItem = Color.FromRgb(0, 255, 0);
+ observableCollection.Add(new CustomColorItem(colorItem, string.Format("#{0},{1},{2}", 0, 255, 0)));
+ return observableCollection;
+ }
+ }
+}
diff --git a/src/DynamoCoreWpf/Views/Core/CustomColorPicker.xaml b/src/DynamoCoreWpf/Views/Core/CustomColorPicker.xaml
new file mode 100644
index 00000000000..b40656c3c3d
--- /dev/null
+++ b/src/DynamoCoreWpf/Views/Core/CustomColorPicker.xaml
@@ -0,0 +1,220 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/DynamoCoreWpf/Views/Core/CustomColorPicker.xaml.cs b/src/DynamoCoreWpf/Views/Core/CustomColorPicker.xaml.cs
new file mode 100644
index 00000000000..ed86f37f8af
--- /dev/null
+++ b/src/DynamoCoreWpf/Views/Core/CustomColorPicker.xaml.cs
@@ -0,0 +1,62 @@
+using System.Linq;
+using System.Windows.Controls;
+using System.Windows.Controls.Primitives;
+using Dynamo.ViewModels;
+
+namespace Dynamo.Controls
+{
+ public partial class CustomColorPicker : Popup
+ {
+ private CustomColorPickerViewModel viewModel;
+
+ public CustomColorPicker()
+ {
+ InitializeComponent();
+ if (viewModel == null)
+ {
+ viewModel = new CustomColorPickerViewModel();
+ }
+ this.DataContext = viewModel;
+ }
+
+ private void Apply_Click(object sender, System.Windows.RoutedEventArgs e)
+ {
+ viewModel.ColorPickerFinalSelectedColor = xceedColorPickerControl.SelectedColor;
+ this.IsOpen = false;
+ }
+
+ private void CancelBtn_Click(object sender, System.Windows.RoutedEventArgs e)
+ {
+ viewModel.ColorPickerFinalSelectedColor = null;
+ this.IsOpen = false;
+ }
+
+ private void CloseButton_Click(object sender, System.Windows.RoutedEventArgs e)
+ {
+ viewModel.ColorPickerFinalSelectedColor = null;
+ this.IsOpen = false;
+ }
+
+ private void PART_BasicColors_SelectionChanged(object sender, SelectionChangedEventArgs e)
+ {
+ SelectColor(sender);
+ }
+
+ private void PART_CustomColors_SelectionChanged(object sender, SelectionChangedEventArgs e)
+ {
+ SelectColor(sender);
+ }
+
+ private void SelectColor(object sender)
+ {
+ var listbox = sender as ListBox;
+ if (listbox == null) return;
+
+ var customColorItemSelected = listbox.SelectedItem as CustomColorItem;
+ if (customColorItemSelected == null) return;
+
+ listbox.Items.Cast().ToList().ForEach(color => color.IsColorItemSelected = false);
+ customColorItemSelected.IsColorItemSelected = true;
+ }
+ }
+}
diff --git a/src/DynamoCoreWpf/Views/Menu/PreferencesView.xaml.cs b/src/DynamoCoreWpf/Views/Menu/PreferencesView.xaml.cs
index 11c77a9cd6d..caa73368efb 100644
--- a/src/DynamoCoreWpf/Views/Menu/PreferencesView.xaml.cs
+++ b/src/DynamoCoreWpf/Views/Menu/PreferencesView.xaml.cs
@@ -30,6 +30,8 @@ public partial class PreferencesView : Window
private readonly DynamoViewModel dynViewModel;
private List originalCustomGroupStyles { get; set; }
+ private Button colorButtonSelected;
+
// Used for tracking the manage package command event
// This is not a command any more but we keep it
// around in a compatible way for now
@@ -255,13 +257,28 @@ private void RemoveStyle_Click(object sender, RoutedEventArgs e)
private void ButtonColorPicker_Click(object sender, RoutedEventArgs e)
{
- System.Windows.Forms.ColorDialog colorDialog = new System.Windows.Forms.ColorDialog();
+ var colorPicker = new CustomColorPicker();
+ if (colorPicker == null) return;
- if (colorDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
+ colorPicker.Placement = PlacementMode.Top;
+ colorPicker.PlacementTarget = sender as UIElement;
+ colorPicker.IsOpen = true;
+ colorPicker.Closed += ColorPicker_Closed;
+ colorButtonSelected = sender as Button;
+ }
+
+ private void ColorPicker_Closed(object sender, EventArgs e)
+ {
+ var colorPicker = sender as CustomColorPicker;
+ if(colorPicker == null) return;
+ colorPicker.Closed -= ColorPicker_Closed;
+
+ if (colorButtonSelected != null)
{
- Button colorButton = sender as Button;
- if (colorButton != null)
- colorButton.Background = new SolidColorBrush(Color.FromRgb(colorDialog.Color.R, colorDialog.Color.G, colorDialog.Color.B));
+ var viewModel = colorPicker.DataContext as CustomColorPickerViewModel;
+ if (viewModel == null || viewModel.ColorPickerFinalSelectedColor == null)
+ return;
+ colorButtonSelected.Background = new SolidColorBrush(viewModel.ColorPickerFinalSelectedColor.Value);
}
}
diff --git a/src/Libraries/CoreNodeModelsWpf/ColorPaletteViewModel.cs b/src/Libraries/CoreNodeModelsWpf/ColorPaletteViewModel.cs
new file mode 100644
index 00000000000..14ab844552e
--- /dev/null
+++ b/src/Libraries/CoreNodeModelsWpf/ColorPaletteViewModel.cs
@@ -0,0 +1,26 @@
+using System.Windows.Media;
+using Dynamo.Core;
+
+namespace Dynamo.Wpf
+{
+ internal class ColorPaletteViewModel : NotificationObject
+ {
+ private SolidColorBrush selectedColor;
+
+ ///
+ /// This Property will contain the selected color in the CustomColorPicker popup
+ ///
+ public SolidColorBrush SelectedColor
+ {
+ get
+ {
+ return selectedColor;
+ }
+ set
+ {
+ selectedColor = value;
+ RaisePropertyChanged(nameof(SelectedColor));
+ }
+ }
+ }
+}
diff --git a/src/Libraries/CoreNodeModelsWpf/Controls/ColorPalette.xaml b/src/Libraries/CoreNodeModelsWpf/Controls/ColorPalette.xaml
index 75d7d7d3081..625fd78f336 100644
--- a/src/Libraries/CoreNodeModelsWpf/Controls/ColorPalette.xaml
+++ b/src/Libraries/CoreNodeModelsWpf/Controls/ColorPalette.xaml
@@ -1,25 +1,65 @@
-
+
+
+
+
+
+
diff --git a/src/Libraries/CoreNodeModelsWpf/Controls/ColorPalette.xaml.cs b/src/Libraries/CoreNodeModelsWpf/Controls/ColorPalette.xaml.cs
index 03c5becfe51..6bf4825cee3 100644
--- a/src/Libraries/CoreNodeModelsWpf/Controls/ColorPalette.xaml.cs
+++ b/src/Libraries/CoreNodeModelsWpf/Controls/ColorPalette.xaml.cs
@@ -1,4 +1,9 @@
-using System.Windows.Controls;
+using System.Windows.Controls;
+using System.Windows.Controls.Primitives;
+using System.Windows.Media;
+using Dynamo.Controls;
+using Dynamo.ViewModels;
+using Dynamo.Wpf;
namespace CoreNodeModelsWpf.Controls
{
@@ -7,9 +12,55 @@ namespace CoreNodeModelsWpf.Controls
///
public partial class ColorPaletteUI : UserControl
{
+
+ ///
+ /// Delegate that will be used for manage the event when a color was selected from the Color Picker
+ ///
+ public delegate void ColorPickerSelectedColorHandler();
+
+ ///
+ /// Event that will be raised when the user selected a color in the CustomColorPicker popup and then the popup is closed
+ ///
+ public event ColorPickerSelectedColorHandler ColorPickerSelectedColor;
+
+ public void OnColorPickerSelectedColor()
+ {
+ this.ColorPickerSelectedColor?.Invoke();
+ }
+
+ private ColorPaletteViewModel viewModel = null;
+
public ColorPaletteUI()
{
InitializeComponent();
+ if(viewModel == null)
+ {
+ viewModel = new ColorPaletteViewModel();
+ }
+ this.DataContext = viewModel;
+
+ //By default the ToggleButton will contain the Black color
+ viewModel.SelectedColor = new SolidColorBrush(Colors.Black);
+ }
+
+ private void ColorPickerPopup_Closed(object sender, System.EventArgs e)
+ {
+ var colorPickerPopupClosed = sender as CustomColorPicker;
+ colorPickerPopupClosed.Closed -= ColorPickerPopup_Closed;
+ var colorPickerViewModel = colorPickerPopupClosed.DataContext as CustomColorPickerViewModel;
+ if (colorPickerViewModel == null || colorPickerViewModel.ColorPickerFinalSelectedColor == null) return;
+
+ viewModel.SelectedColor = new SolidColorBrush(colorPickerViewModel.ColorPickerFinalSelectedColor.Value);
+ OnColorPickerSelectedColor();
+ }
+
+ private void ColorToggleButton_Click(object sender, System.Windows.RoutedEventArgs e)
+ {
+ var colorPickerPopup = new CustomColorPicker();
+ colorPickerPopup.Placement = PlacementMode.Bottom;
+ colorPickerPopup.PlacementTarget = ColorToggleButton;
+ colorPickerPopup.IsOpen = true;
+ colorPickerPopup.Closed += ColorPickerPopup_Closed;
}
}
}
diff --git a/src/Libraries/CoreNodeModelsWpf/CoreNodeModelsWpf.csproj b/src/Libraries/CoreNodeModelsWpf/CoreNodeModelsWpf.csproj
index 0e597d58fb8..aaebfaf3e5d 100644
--- a/src/Libraries/CoreNodeModelsWpf/CoreNodeModelsWpf.csproj
+++ b/src/Libraries/CoreNodeModelsWpf/CoreNodeModelsWpf.csproj
@@ -35,11 +35,6 @@
-
- true
-
- runtime
-
diff --git a/src/Libraries/CoreNodeModelsWpf/NodeViewCustomizations/ColorPalette.cs b/src/Libraries/CoreNodeModelsWpf/NodeViewCustomizations/ColorPalette.cs
index 8b0694c537b..b924fa0c387 100644
--- a/src/Libraries/CoreNodeModelsWpf/NodeViewCustomizations/ColorPalette.cs
+++ b/src/Libraries/CoreNodeModelsWpf/NodeViewCustomizations/ColorPalette.cs
@@ -1,4 +1,4 @@
-using System.ComponentModel;
+using System.ComponentModel;
using System.Windows;
using System.Windows.Media;
using CoreNodeModels.Input;
@@ -20,6 +20,7 @@ public class ColorPaletteNodeViewCustomization : NotificationObject, INodeViewCu
private NodeView viewNode;
private ColorPalette colorPaletteNode;
private Converters.MediatoDSColorConverter converter;
+ private ColorPaletteViewModel colorPaletteViewModel;
///
/// Customize View.
///
@@ -31,9 +32,12 @@ public void CustomizeView(ColorPalette model, NodeView nodeView)
colorPaletteNode = model;
converter = new Converters.MediatoDSColorConverter();
ColorPaletteUINode = new ColorPaletteUI();
+ colorPaletteViewModel = ColorPaletteUINode.DataContext as ColorPaletteViewModel;
+ if(colorPaletteNode == null ) return;
+
ColorPaletteUINode.HorizontalAlignment = HorizontalAlignment.Left;
ColorPaletteUINode.VerticalAlignment = VerticalAlignment.Top;
- ColorPaletteUINode.xceedColorPickerControl.Closed += ColorPickerControl_Closed;
+ ColorPaletteUINode.ColorPickerSelectedColor += ColorPaletteUINode_ColorPickerSelectedColor;
colorPaletteNode.PropertyChanged += ColorPaletteNode_PropertyChanged;
nodeView.ContentGrid.Children.Add(ColorPaletteUINode);
@@ -41,39 +45,39 @@ public void CustomizeView(ColorPalette model, NodeView nodeView)
this.ColorPaletteNode_PropertyChanged(ColorPaletteUINode, new PropertyChangedEventArgs("DsColor"));
}
+
private void ColorPaletteNode_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
//if the property name was DsColor
- if (e.PropertyName == "DsColor")
+ if (e.PropertyName == "DsColor")
{
-
var convertedModelColor = ((Color)(converter.Convert(colorPaletteNode.DsColor, null, null, null)));
var isSameColor = convertedModelColor
- .Equals(ColorPaletteUINode.xceedColorPickerControl.SelectedColor);
+ .Equals(colorPaletteViewModel.SelectedColor);
//and if the color on the model is different than the selected Color on the view
//then update the view.
if (!isSameColor)
{
- ColorPaletteUINode.xceedColorPickerControl.SelectedColor = convertedModelColor;
+ colorPaletteViewModel.SelectedColor = new SolidColorBrush(convertedModelColor);
}
}
}
- private void ColorPickerControl_Closed(object sender, System.Windows.RoutedEventArgs e)
+ private void ColorPaletteUINode_ColorPickerSelectedColor()
{
//if the model color is the same as the selected color when the color control is closed
//we should not record the model for undo again, it's already there.
var convertedModelColor = ((Color)(converter.Convert(colorPaletteNode.DsColor, null, null, null)));
var isSameColor = convertedModelColor
- .Equals(ColorPaletteUINode.xceedColorPickerControl.SelectedColor);
+ .Equals(colorPaletteViewModel.SelectedColor);
- if (ColorPaletteUINode.xceedColorPickerControl.SelectedColor != null && !isSameColor)
+ if (colorPaletteViewModel.SelectedColor != null && !isSameColor)
{
//we need to record the colorPicker node before the model is updated.
var undoRecorder = viewNode.ViewModel.WorkspaceViewModel.Model.UndoRecorder;
WorkspaceModel.RecordModelForModification(colorPaletteNode, undoRecorder);
//now that we have recorded the old state, set the color on the model.
- colorPaletteNode.DsColor = converter.ConvertBack(ColorPaletteUINode.xceedColorPickerControl.SelectedColor, null, null, null) as DSColor;
+ colorPaletteNode.DsColor = converter.ConvertBack(colorPaletteViewModel.SelectedColor.Color, null, null, null) as DSColor;
}
}
@@ -82,7 +86,7 @@ private void ColorPickerControl_Closed(object sender, System.Windows.RoutedEvent
///
public void Dispose()
{
- ColorPaletteUINode.xceedColorPickerControl.Closed -= ColorPickerControl_Closed; ;
+ ColorPaletteUINode.ColorPickerSelectedColor -= ColorPaletteUINode_ColorPickerSelectedColor;
colorPaletteNode.PropertyChanged -= ColorPaletteNode_PropertyChanged;
}