From 5d8d996f44b69ccd10b92d589b0dc10909027e74 Mon Sep 17 00:00:00 2001 From: Geoffroy BONNEVILLE Date: Mon, 1 Jun 2020 10:32:06 +0200 Subject: [PATCH] Working ColorPickerUserControl --- .../UserControls/ColorPickerUserControl.xaml | 1 - .../ColorPickerUserControl.xaml.cs | 20 ++++++++----------- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/ModernKeePass/Views/UserControls/ColorPickerUserControl.xaml b/ModernKeePass/Views/UserControls/ColorPickerUserControl.xaml index fcb62ca..2eec378 100644 --- a/ModernKeePass/Views/UserControls/ColorPickerUserControl.xaml +++ b/ModernKeePass/Views/UserControls/ColorPickerUserControl.xaml @@ -11,7 +11,6 @@ SelectedItem="{Binding SelectedItem}" SelectedValue="{Binding SelectedColor, ElementName=UserControl}" SelectedValuePath="ColorBrush" - Loaded="ComboBox_OnLoaded" SelectionChanged="ComboBox_OnSelectionChanged" IsEnabled="{Binding IsEnabled, ElementName=UserControl}"> diff --git a/ModernKeePass/Views/UserControls/ColorPickerUserControl.xaml.cs b/ModernKeePass/Views/UserControls/ColorPickerUserControl.xaml.cs index b3eb866..0db9e59 100644 --- a/ModernKeePass/Views/UserControls/ColorPickerUserControl.xaml.cs +++ b/ModernKeePass/Views/UserControls/ColorPickerUserControl.xaml.cs @@ -1,5 +1,4 @@ -using System.Linq; -using Windows.UI.Xaml; +using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Media; using ModernKeePass.ViewModels; @@ -10,8 +9,6 @@ namespace ModernKeePass.Views.UserControls { public sealed partial class ColorPickerUserControl { - private ColorPickerControlVm Model => ComboBox.DataContext as ColorPickerControlVm; - public SolidColorBrush SelectedColor { get { return (SolidColorBrush)GetValue(SelectedColorProperty); } @@ -22,22 +19,21 @@ namespace ModernKeePass.Views.UserControls nameof(SelectedColor), typeof(SolidColorBrush), typeof(ColorPickerUserControl), - new PropertyMetadata(new SolidColorBrush(), (o, args) => { })); + new PropertyMetadata(new SolidColorBrush(), (o, args) => + { + var colorPickerUserControl = o as ColorPickerUserControl; + var vm = colorPickerUserControl?.ComboBox.DataContext as ColorPickerControlVm; + vm?.Initialize(args.NewValue as SolidColorBrush); + })); public ColorPickerUserControl() { InitializeComponent(); } - private void ComboBox_OnLoaded(object sender, RoutedEventArgs e) - { - Model.Initialize(SelectedColor); - } - private void ComboBox_OnSelectionChanged(object sender, SelectionChangedEventArgs e) { - if (e.RemovedItems.Any()) - SelectedColor = ComboBox.SelectedValue as SolidColorBrush; + SelectedColor = (e.AddedItems[0] as ColorPickerControlVm.Color)?.ColorBrush; } } }