ColorPickerControl finally doesn't set database to dirty when there is an initial value

This commit is contained in:
Geoffroy BONNEVILLE
2020-05-20 17:40:06 +02:00
parent 643fb9a3f2
commit 45b5ae5630
5 changed files with 81 additions and 25 deletions

View File

@@ -6,10 +6,14 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<ComboBox x:Name="ComboBox"
ItemsSource="{Binding Colors, ElementName=UserControl}"
SelectedValue="{Binding SelectedColor, ElementName=UserControl, Mode=TwoWay}"
SelectedValuePath="ColorBrush"
IsEnabled="{Binding IsEnabled, ElementName=UserControl}">
DataContext="{Binding Source={StaticResource Locator}, Path=ColorPicker}"
ItemsSource="{Binding Colors}"
SelectedItem="{Binding SelectedItem}"
SelectedValue="{Binding SelectedColor, ElementName=UserControl}"
SelectedValuePath="ColorBrush"
Loaded="ComboBox_OnLoaded"
SelectionChanged="ComboBox_OnSelectionChanged"
IsEnabled="{Binding IsEnabled, ElementName=UserControl}">
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Margin="0,0,10,0">

View File

@@ -1,9 +1,8 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Linq;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media;
using ModernKeePass.ViewModels;
// The User Control item template is documented at http://go.microsoft.com/fwlink/?LinkId=234236
@@ -11,13 +10,7 @@ namespace ModernKeePass.Views.UserControls
{
public sealed partial class ColorPickerUserControl
{
public struct Color
{
public string ColorName { get; set; }
public SolidColorBrush ColorBrush { get; set; }
}
public List<Color> Colors { get; }
private ColorPickerControlVm Model => ComboBox.DataContext as ColorPickerControlVm;
public SolidColorBrush SelectedColor
{
@@ -34,17 +27,17 @@ namespace ModernKeePass.Views.UserControls
public ColorPickerUserControl()
{
InitializeComponent();
Colors = new List<Color>();
var type = typeof(Windows.UI.Colors);
var properties = type.GetRuntimeProperties().ToArray();
foreach (var propertyInfo in properties)
{
Colors.Add(new Color
{
ColorName = propertyInfo.Name,
ColorBrush = new SolidColorBrush((Windows.UI.Color)propertyInfo.GetValue(null, null))
});
}
}
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;
}
}
}