Finally a nicer looking and working TextBoxWithButton (inspired from the SearchButton)

SearchBox field style improved
This commit is contained in:
Geoffroy BONNEVILLE
2020-04-28 15:20:47 +02:00
parent 8e06bf4bb0
commit f158e5aced
24 changed files with 481 additions and 283 deletions

View File

@@ -1,10 +1,11 @@
using System;
using System.Windows.Input;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
namespace ModernKeePass.Controls
{
public class TextBoxWithButton : TextBox
public class TextBoxWithButton : Control
{
public event EventHandler<RoutedEventArgs> ButtonClick;
@@ -15,7 +16,7 @@ namespace ModernKeePass.Controls
}
public static readonly DependencyProperty ButtonSymbolProperty =
DependencyProperty.Register(
"ButtonSymbol",
nameof(ButtonSymbol),
typeof(string),
typeof(TextBoxWithButton),
new PropertyMetadata("&#xE107;", (o, args) => { }));
@@ -27,11 +28,46 @@ namespace ModernKeePass.Controls
}
public static readonly DependencyProperty ButtonTooltipProperty =
DependencyProperty.Register(
"ButtonTooltip",
nameof(ButtonTooltip),
typeof(string),
typeof(TextBoxWithButton),
new PropertyMetadata(string.Empty, (o, args) => { }));
public string Text
{
get { return (string)GetValue(TextProperty); }
set { SetValue(TextProperty, value); }
}
public static readonly DependencyProperty TextProperty =
DependencyProperty.Register(
nameof(Text),
typeof(string),
typeof(TextBoxWithButton),
new PropertyMetadata(string.Empty, (o, args) => { }));
public string PlaceholderText
{
get { return (string)GetValue(PlaceholderTextProperty); }
set { SetValue(PlaceholderTextProperty, value); }
}
public static readonly DependencyProperty PlaceholderTextProperty =
DependencyProperty.Register(
nameof(PlaceholderText),
typeof(string),
typeof(TextBoxWithButton),
new PropertyMetadata(string.Empty, (o, args) => { }));
public ICommand ButtonCommand
{
get { return (ICommand)GetValue(ButtonCommandProperty); }
set { SetValue(ButtonCommandProperty, value); }
}
public static readonly DependencyProperty ButtonCommandProperty =
DependencyProperty.Register(
nameof(ButtonCommand),
typeof(ICommand),
typeof(TextBoxWithButton),
new PropertyMetadata(null, (o, args) => { }));
public bool IsButtonEnabled
{
get { return (bool)GetValue(IsButtonEnabledProperty); }
@@ -44,6 +80,11 @@ namespace ModernKeePass.Controls
typeof(TextBoxWithButton),
new PropertyMetadata(true, (o, args) => { }));
public TextBoxWithButton()
{
DefaultStyleKey = typeof(TextBoxWithButton);
}
protected override void OnApplyTemplate()
{
base.OnApplyTemplate();

View File

@@ -0,0 +1,20 @@
using System.Collections.Generic;
using MediatR;
using ModernKeePass.Application.Database.Queries.GetDatabase;
using ModernKeePass.Application.Group.Models;
using ModernKeePass.Application.Group.Queries.GetAllGroups;
namespace ModernKeePass.ViewModels
{
public class TopMenuVm
{
public IEnumerable<GroupVm> Groups { get; set; }
public string SelectedDestinationGroup { get; set; }
public TopMenuVm(IMediator mediator)
{
var database = mediator.Send(new GetDatabaseQuery()).GetAwaiter().GetResult();
Groups = mediator.Send(new GetAllGroupsQuery { GroupId = database.RootGroupId }).GetAwaiter().GetResult();
}
}
}

View File

@@ -63,6 +63,7 @@ namespace ModernKeePass.ViewModels
SimpleIoc.Default.Register<SettingsSecurityVm>();
SimpleIoc.Default.Register<OpenDatabaseControlVm>();
SimpleIoc.Default.Register<SetCredentialsVm>();
SimpleIoc.Default.Register<TopMenuVm>();
SimpleIoc.Default.Register<MainVm>();
SimpleIoc.Default.Register<NewVm>();
SimpleIoc.Default.Register<OpenVm>();
@@ -80,6 +81,7 @@ namespace ModernKeePass.ViewModels
public SettingsSecurityVm SettingsSecurity => ServiceLocator.Current.GetInstance<SettingsSecurityVm>(Guid.NewGuid().ToString());
public OpenDatabaseControlVm OpenDatabaseControl => ServiceLocator.Current.GetInstance<OpenDatabaseControlVm>(Guid.NewGuid().ToString());
public SetCredentialsVm SetCredentials => ServiceLocator.Current.GetInstance<SetCredentialsVm>(Guid.NewGuid().ToString());
public TopMenuVm TopMenu => ServiceLocator.Current.GetInstance<TopMenuVm>(Guid.NewGuid().ToString());
public NewVm New => ServiceLocator.Current.GetInstance<NewVm>(Guid.NewGuid().ToString());
public OpenVm Open => ServiceLocator.Current.GetInstance<OpenVm>(Guid.NewGuid().ToString());
public RecentVm Recent => ServiceLocator.Current.GetInstance<RecentVm>(Guid.NewGuid().ToString());

View File

@@ -55,6 +55,7 @@
<Compile Include="$(MSBuildThisFileDirectory)ViewModels\SaveVm.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ViewModels\UserControls\OpenDatabaseControlVm.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ViewModels\UserControls\SetCredentialsVm.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ViewModels\UserControls\TopMenuVm.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ViewModels\ViewModelLocator.cs" />
</ItemGroup>
</Project>