mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-03 15:40:18 -04:00
ColorPickerControl finally doesn't set database to dirty when there is an initial value
This commit is contained in:
@@ -6,9 +6,13 @@
|
|||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
mc:Ignorable="d">
|
mc:Ignorable="d">
|
||||||
<ComboBox x:Name="ComboBox"
|
<ComboBox x:Name="ComboBox"
|
||||||
ItemsSource="{Binding Colors, ElementName=UserControl}"
|
DataContext="{Binding Source={StaticResource Locator}, Path=ColorPicker}"
|
||||||
SelectedValue="{Binding SelectedColor, ElementName=UserControl, Mode=TwoWay}"
|
ItemsSource="{Binding Colors}"
|
||||||
|
SelectedItem="{Binding SelectedItem}"
|
||||||
|
SelectedValue="{Binding SelectedColor, ElementName=UserControl}"
|
||||||
SelectedValuePath="ColorBrush"
|
SelectedValuePath="ColorBrush"
|
||||||
|
Loaded="ComboBox_OnLoaded"
|
||||||
|
SelectionChanged="ComboBox_OnSelectionChanged"
|
||||||
IsEnabled="{Binding IsEnabled, ElementName=UserControl}">
|
IsEnabled="{Binding IsEnabled, ElementName=UserControl}">
|
||||||
<ComboBox.ItemTemplate>
|
<ComboBox.ItemTemplate>
|
||||||
<DataTemplate>
|
<DataTemplate>
|
||||||
|
@@ -1,9 +1,8 @@
|
|||||||
using System.Collections.Generic;
|
using System.Linq;
|
||||||
using System.Linq;
|
|
||||||
using System.Reflection;
|
|
||||||
using Windows.UI.Xaml;
|
using Windows.UI.Xaml;
|
||||||
using Windows.UI.Xaml.Controls;
|
using Windows.UI.Xaml.Controls;
|
||||||
using Windows.UI.Xaml.Media;
|
using Windows.UI.Xaml.Media;
|
||||||
|
using ModernKeePass.ViewModels;
|
||||||
|
|
||||||
// The User Control item template is documented at http://go.microsoft.com/fwlink/?LinkId=234236
|
// 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 sealed partial class ColorPickerUserControl
|
||||||
{
|
{
|
||||||
public struct Color
|
private ColorPickerControlVm Model => ComboBox.DataContext as ColorPickerControlVm;
|
||||||
{
|
|
||||||
public string ColorName { get; set; }
|
|
||||||
public SolidColorBrush ColorBrush { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Color> Colors { get; }
|
|
||||||
|
|
||||||
public SolidColorBrush SelectedColor
|
public SolidColorBrush SelectedColor
|
||||||
{
|
{
|
||||||
@@ -34,17 +27,17 @@ namespace ModernKeePass.Views.UserControls
|
|||||||
public ColorPickerUserControl()
|
public ColorPickerUserControl()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
56
WinAppCommon/ViewModels/UserControls/ColorPickerControlVm.cs
Normal file
56
WinAppCommon/ViewModels/UserControls/ColorPickerControlVm.cs
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
|
using Windows.UI.Xaml.Media;
|
||||||
|
using GalaSoft.MvvmLight;
|
||||||
|
|
||||||
|
namespace ModernKeePass.ViewModels
|
||||||
|
{
|
||||||
|
public class ColorPickerControlVm: ObservableObject
|
||||||
|
{
|
||||||
|
private Color _selectedItem;
|
||||||
|
|
||||||
|
public class Color
|
||||||
|
{
|
||||||
|
public string ColorName { get; set; }
|
||||||
|
public SolidColorBrush ColorBrush { get; set; }
|
||||||
|
|
||||||
|
public bool Equals(SolidColorBrush color)
|
||||||
|
{
|
||||||
|
return color.Color.R == ColorBrush.Color.R &&
|
||||||
|
color.Color.G == ColorBrush.Color.G &&
|
||||||
|
color.Color.B == ColorBrush.Color.B &&
|
||||||
|
color.Color.A == ColorBrush.Color.A;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Color> Colors { get; }
|
||||||
|
|
||||||
|
public Color SelectedItem
|
||||||
|
{
|
||||||
|
get { return _selectedItem; }
|
||||||
|
set { Set(() => SelectedItem, ref _selectedItem, value); }
|
||||||
|
}
|
||||||
|
|
||||||
|
public ColorPickerControlVm()
|
||||||
|
{
|
||||||
|
Colors = new List<Color>();
|
||||||
|
var type = typeof(Windows.UI.Colors);
|
||||||
|
var properties = type.GetRuntimeProperties().ToArray();
|
||||||
|
foreach (var propertyInfo in properties)
|
||||||
|
{
|
||||||
|
var color = new Color
|
||||||
|
{
|
||||||
|
ColorName = propertyInfo.Name,
|
||||||
|
ColorBrush = new SolidColorBrush((Windows.UI.Color) propertyInfo.GetValue(null, null))
|
||||||
|
};
|
||||||
|
Colors.Add(color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Initialize(SolidColorBrush selectedColor)
|
||||||
|
{
|
||||||
|
SelectedItem = Colors.FirstOrDefault(c => c.Equals(selectedColor));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -67,6 +67,7 @@ namespace ModernKeePass.ViewModels
|
|||||||
SimpleIoc.Default.Register<OpenDatabaseControlVm>();
|
SimpleIoc.Default.Register<OpenDatabaseControlVm>();
|
||||||
SimpleIoc.Default.Register<SetCredentialsVm>();
|
SimpleIoc.Default.Register<SetCredentialsVm>();
|
||||||
SimpleIoc.Default.Register<TopMenuVm>();
|
SimpleIoc.Default.Register<TopMenuVm>();
|
||||||
|
SimpleIoc.Default.Register<ColorPickerControlVm>();
|
||||||
SimpleIoc.Default.Register<NewVm>();
|
SimpleIoc.Default.Register<NewVm>();
|
||||||
SimpleIoc.Default.Register<OpenVm>();
|
SimpleIoc.Default.Register<OpenVm>();
|
||||||
SimpleIoc.Default.Register<RecentVm>();
|
SimpleIoc.Default.Register<RecentVm>();
|
||||||
@@ -82,6 +83,7 @@ namespace ModernKeePass.ViewModels
|
|||||||
public OpenDatabaseControlVm OpenDatabaseControl => ServiceLocator.Current.GetInstance<OpenDatabaseControlVm>(Guid.NewGuid().ToString());
|
public OpenDatabaseControlVm OpenDatabaseControl => ServiceLocator.Current.GetInstance<OpenDatabaseControlVm>(Guid.NewGuid().ToString());
|
||||||
public SetCredentialsVm SetCredentials => ServiceLocator.Current.GetInstance<SetCredentialsVm>(Guid.NewGuid().ToString());
|
public SetCredentialsVm SetCredentials => ServiceLocator.Current.GetInstance<SetCredentialsVm>(Guid.NewGuid().ToString());
|
||||||
public TopMenuVm TopMenu => ServiceLocator.Current.GetInstance<TopMenuVm>(Guid.NewGuid().ToString());
|
public TopMenuVm TopMenu => ServiceLocator.Current.GetInstance<TopMenuVm>(Guid.NewGuid().ToString());
|
||||||
|
public ColorPickerControlVm ColorPicker => ServiceLocator.Current.GetInstance<ColorPickerControlVm>(Guid.NewGuid().ToString());
|
||||||
public NewVm New => ServiceLocator.Current.GetInstance<NewVm>(Guid.NewGuid().ToString());
|
public NewVm New => ServiceLocator.Current.GetInstance<NewVm>(Guid.NewGuid().ToString());
|
||||||
public OpenVm Open => ServiceLocator.Current.GetInstance<OpenVm>(Guid.NewGuid().ToString());
|
public OpenVm Open => ServiceLocator.Current.GetInstance<OpenVm>(Guid.NewGuid().ToString());
|
||||||
public RecentVm Recent => ServiceLocator.Current.GetInstance<RecentVm>(Guid.NewGuid().ToString());
|
public RecentVm Recent => ServiceLocator.Current.GetInstance<RecentVm>(Guid.NewGuid().ToString());
|
||||||
|
@@ -49,6 +49,7 @@
|
|||||||
<Compile Include="$(MSBuildThisFileDirectory)ViewModels\Settings\RecycleBinVm.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)ViewModels\Settings\RecycleBinVm.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)ViewModels\Settings\GeneralVm.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)ViewModels\Settings\GeneralVm.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)ViewModels\Settings\SecurityVm.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)ViewModels\Settings\SecurityVm.cs" />
|
||||||
|
<Compile Include="$(MSBuildThisFileDirectory)ViewModels\UserControls\ColorPickerControlVm.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)ViewModels\ViewModelLocatorCommon.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)ViewModels\ViewModelLocatorCommon.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)ViewModels\Items\ListMenuItemVm.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)ViewModels\Items\ListMenuItemVm.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)ViewModels\Items\MainMenuItemVm.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)ViewModels\Items\MainMenuItemVm.cs" />
|
||||||
|
Reference in New Issue
Block a user