2017-10-12 17:30:29 +02:00
|
|
|
|
using System;
|
2020-04-28 15:20:47 +02:00
|
|
|
|
using System.Windows.Input;
|
2017-10-12 17:30:29 +02:00
|
|
|
|
using Windows.UI.Xaml;
|
|
|
|
|
using Windows.UI.Xaml.Controls;
|
|
|
|
|
|
|
|
|
|
namespace ModernKeePass.Controls
|
|
|
|
|
{
|
2020-04-28 15:20:47 +02:00
|
|
|
|
public class TextBoxWithButton : Control
|
2017-10-12 17:30:29 +02:00
|
|
|
|
{
|
2018-07-30 16:29:28 +02:00
|
|
|
|
public event EventHandler<RoutedEventArgs> ButtonClick;
|
|
|
|
|
|
2017-11-27 15:26:36 +01:00
|
|
|
|
public string ButtonSymbol
|
2017-11-06 19:01:01 +01:00
|
|
|
|
{
|
2017-11-27 15:26:36 +01:00
|
|
|
|
get { return (string)GetValue(ButtonSymbolProperty); }
|
2017-11-06 19:01:01 +01:00
|
|
|
|
set { SetValue(ButtonSymbolProperty, value); }
|
|
|
|
|
}
|
|
|
|
|
public static readonly DependencyProperty ButtonSymbolProperty =
|
|
|
|
|
DependencyProperty.Register(
|
2020-04-28 15:20:47 +02:00
|
|
|
|
nameof(ButtonSymbol),
|
2017-11-27 15:26:36 +01:00
|
|
|
|
typeof(string),
|
2017-11-06 19:01:01 +01:00
|
|
|
|
typeof(TextBoxWithButton),
|
2017-11-27 15:26:36 +01:00
|
|
|
|
new PropertyMetadata("", (o, args) => { }));
|
2017-11-06 19:01:01 +01:00
|
|
|
|
|
2017-11-27 15:26:36 +01:00
|
|
|
|
public string ButtonTooltip
|
2017-11-06 19:01:01 +01:00
|
|
|
|
{
|
2017-11-27 15:26:36 +01:00
|
|
|
|
get { return (string)GetValue(ButtonTooltipProperty); }
|
|
|
|
|
set { SetValue(ButtonTooltipProperty, value); }
|
2017-11-06 19:01:01 +01:00
|
|
|
|
}
|
2017-11-27 15:26:36 +01:00
|
|
|
|
public static readonly DependencyProperty ButtonTooltipProperty =
|
2017-11-06 19:01:01 +01:00
|
|
|
|
DependencyProperty.Register(
|
2020-04-28 15:20:47 +02:00
|
|
|
|
nameof(ButtonTooltip),
|
2017-11-06 19:01:01 +01:00
|
|
|
|
typeof(string),
|
|
|
|
|
typeof(TextBoxWithButton),
|
2017-11-27 15:26:36 +01:00
|
|
|
|
new PropertyMetadata(string.Empty, (o, args) => { }));
|
2017-10-12 17:30:29 +02:00
|
|
|
|
|
2020-04-28 15:20:47 +02:00
|
|
|
|
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) => { }));
|
|
|
|
|
|
2017-12-11 19:00:14 +01:00
|
|
|
|
public bool IsButtonEnabled
|
|
|
|
|
{
|
|
|
|
|
get { return (bool)GetValue(IsButtonEnabledProperty); }
|
|
|
|
|
set { SetValue(IsButtonEnabledProperty, value); }
|
|
|
|
|
}
|
|
|
|
|
public static readonly DependencyProperty IsButtonEnabledProperty =
|
|
|
|
|
DependencyProperty.Register(
|
|
|
|
|
"IsButtonEnabled",
|
|
|
|
|
typeof(bool),
|
|
|
|
|
typeof(TextBoxWithButton),
|
|
|
|
|
new PropertyMetadata(true, (o, args) => { }));
|
2018-07-11 12:15:56 +02:00
|
|
|
|
|
2020-04-28 15:20:47 +02:00
|
|
|
|
|
|
|
|
|
public TextBoxWithButton()
|
|
|
|
|
{
|
|
|
|
|
DefaultStyleKey = typeof(TextBoxWithButton);
|
|
|
|
|
}
|
2017-10-12 17:30:29 +02:00
|
|
|
|
protected override void OnApplyTemplate()
|
|
|
|
|
{
|
|
|
|
|
base.OnApplyTemplate();
|
2017-11-06 19:01:01 +01:00
|
|
|
|
var actionButton = GetTemplateChild("ActionButton") as Button;
|
|
|
|
|
if (actionButton != null)
|
2017-10-12 17:30:29 +02:00
|
|
|
|
{
|
2017-11-06 19:01:01 +01:00
|
|
|
|
actionButton.Click += (sender, e) => ButtonClick?.Invoke(sender, e);
|
2017-10-12 17:30:29 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|