2018-07-26 12:01:49 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2020-04-28 15:20:47 +02:00
|
|
|
|
using System.Windows.Input;
|
2020-05-05 15:27:34 +02:00
|
|
|
|
using Windows.System;
|
2018-06-14 18:38:05 +02:00
|
|
|
|
using Windows.UI.Xaml;
|
|
|
|
|
using Windows.UI.Xaml.Controls;
|
2020-05-05 15:27:34 +02:00
|
|
|
|
using Windows.UI.Xaml.Input;
|
2020-03-30 19:43:04 +02:00
|
|
|
|
using ModernKeePass.Application.Common.Interfaces;
|
2020-05-05 15:27:34 +02:00
|
|
|
|
using ModernKeePass.Controls;
|
2018-06-14 18:38:05 +02:00
|
|
|
|
|
|
|
|
|
// The User Control item template is documented at http://go.microsoft.com/fwlink/?LinkId=234236
|
|
|
|
|
|
|
|
|
|
namespace ModernKeePass.Views.UserControls
|
|
|
|
|
{
|
|
|
|
|
public sealed partial class HamburgerMenuUserControl
|
|
|
|
|
{
|
|
|
|
|
public string HeaderLabel
|
|
|
|
|
{
|
|
|
|
|
get { return (string)GetValue(HeaderLabelProperty); }
|
|
|
|
|
set { SetValue(HeaderLabelProperty, value); }
|
|
|
|
|
}
|
|
|
|
|
public static readonly DependencyProperty HeaderLabelProperty =
|
|
|
|
|
DependencyProperty.Register(
|
2020-04-14 13:44:07 +02:00
|
|
|
|
nameof(HeaderLabel),
|
2018-06-14 18:38:05 +02:00
|
|
|
|
typeof(string),
|
|
|
|
|
typeof(HamburgerMenuUserControl),
|
|
|
|
|
new PropertyMetadata("Header", (o, args) => { }));
|
|
|
|
|
|
|
|
|
|
public string ButtonLabel
|
|
|
|
|
{
|
|
|
|
|
get { return (string)GetValue(ButtonLabelProperty); }
|
|
|
|
|
set { SetValue(ButtonLabelProperty, value); }
|
|
|
|
|
}
|
|
|
|
|
public static readonly DependencyProperty ButtonLabelProperty =
|
|
|
|
|
DependencyProperty.Register(
|
2020-04-14 13:44:07 +02:00
|
|
|
|
nameof(ButtonLabel),
|
2018-06-14 18:38:05 +02:00
|
|
|
|
typeof(string),
|
|
|
|
|
typeof(HamburgerMenuUserControl),
|
|
|
|
|
new PropertyMetadata("Button", (o, args) => { }));
|
|
|
|
|
|
2018-06-15 10:10:48 +02:00
|
|
|
|
public string DisplayMemberPath
|
|
|
|
|
{
|
|
|
|
|
get { return (string)GetValue(DisplayMemberPathProperty); }
|
|
|
|
|
set { SetValue(DisplayMemberPathProperty, value); }
|
|
|
|
|
}
|
|
|
|
|
public static readonly DependencyProperty DisplayMemberPathProperty =
|
|
|
|
|
DependencyProperty.Register(
|
2020-04-14 13:44:07 +02:00
|
|
|
|
nameof(DisplayMemberPath),
|
2018-06-15 10:10:48 +02:00
|
|
|
|
typeof(string),
|
|
|
|
|
typeof(HamburgerMenuUserControl),
|
2018-06-15 18:07:44 +02:00
|
|
|
|
new PropertyMetadata("Title", (o, args) => { }));
|
2020-05-04 20:56:19 +02:00
|
|
|
|
|
2018-06-15 18:07:44 +02:00
|
|
|
|
public Visibility IsButtonVisible
|
2018-06-15 10:10:48 +02:00
|
|
|
|
{
|
2018-06-15 18:07:44 +02:00
|
|
|
|
get { return (Visibility)GetValue(IsButtonVisibleProperty); }
|
2018-06-15 10:10:48 +02:00
|
|
|
|
set { SetValue(IsButtonVisibleProperty, value); }
|
|
|
|
|
}
|
|
|
|
|
public static readonly DependencyProperty IsButtonVisibleProperty =
|
|
|
|
|
DependencyProperty.Register(
|
2020-04-14 13:44:07 +02:00
|
|
|
|
nameof(IsButtonVisible),
|
2018-06-15 18:07:44 +02:00
|
|
|
|
typeof(Visibility),
|
2018-06-15 10:10:48 +02:00
|
|
|
|
typeof(HamburgerMenuUserControl),
|
2018-06-15 18:07:44 +02:00
|
|
|
|
new PropertyMetadata(Visibility.Collapsed, (o, args) => { }));
|
2018-06-15 10:10:48 +02:00
|
|
|
|
|
2020-03-30 19:43:04 +02:00
|
|
|
|
public IEnumerable<IEntityVm> ItemsSource
|
2018-06-14 18:38:05 +02:00
|
|
|
|
{
|
2020-03-30 19:43:04 +02:00
|
|
|
|
get { return (IEnumerable<IEntityVm>)GetValue(ItemsSourceProperty); }
|
2018-06-14 18:38:05 +02:00
|
|
|
|
set { SetValue(ItemsSourceProperty, value); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static readonly DependencyProperty ItemsSourceProperty =
|
|
|
|
|
DependencyProperty.Register(
|
2020-04-14 13:44:07 +02:00
|
|
|
|
nameof(ItemsSource),
|
2020-03-30 19:43:04 +02:00
|
|
|
|
typeof(IEnumerable<IEntityVm>),
|
2018-06-14 18:38:05 +02:00
|
|
|
|
typeof(HamburgerMenuUserControl),
|
2020-03-30 19:43:04 +02:00
|
|
|
|
new PropertyMetadata(new List<IEntityVm>(), (o, args) => { }));
|
2018-06-14 18:38:05 +02:00
|
|
|
|
|
2018-06-15 18:07:44 +02:00
|
|
|
|
public object SelectedItem
|
|
|
|
|
{
|
|
|
|
|
get { return GetValue(SelectedItemProperty); }
|
|
|
|
|
set { SetValue(SelectedItemProperty, value); }
|
|
|
|
|
}
|
|
|
|
|
public static readonly DependencyProperty SelectedItemProperty =
|
|
|
|
|
DependencyProperty.Register(
|
2020-04-14 13:44:07 +02:00
|
|
|
|
nameof(SelectedItem),
|
2018-06-15 18:07:44 +02:00
|
|
|
|
typeof(object),
|
|
|
|
|
typeof(HamburgerMenuUserControl),
|
|
|
|
|
new PropertyMetadata(null, (o, args) => { }));
|
|
|
|
|
|
2020-04-16 14:08:50 +02:00
|
|
|
|
public int SelectedIndex
|
|
|
|
|
{
|
|
|
|
|
get { return (int)GetValue(SelectedIndexProperty); }
|
|
|
|
|
set { SetValue(SelectedIndexProperty, value); }
|
|
|
|
|
}
|
|
|
|
|
public static readonly DependencyProperty SelectedIndexProperty =
|
|
|
|
|
DependencyProperty.Register(
|
|
|
|
|
nameof(SelectedIndex),
|
|
|
|
|
typeof(int),
|
|
|
|
|
typeof(HamburgerMenuUserControl),
|
|
|
|
|
new PropertyMetadata(-1, (o, args) => { }));
|
2020-05-04 20:56:19 +02:00
|
|
|
|
|
2020-05-05 16:59:49 +02:00
|
|
|
|
public bool IsOpen
|
|
|
|
|
{
|
|
|
|
|
get { return (bool)GetValue(IsOpenProperty); }
|
|
|
|
|
set { SetValue(IsOpenProperty, value); }
|
|
|
|
|
}
|
|
|
|
|
public static readonly DependencyProperty IsOpenProperty =
|
|
|
|
|
DependencyProperty.Register(
|
|
|
|
|
nameof(IsOpen),
|
|
|
|
|
typeof(bool),
|
|
|
|
|
typeof(HamburgerMenuUserControl),
|
|
|
|
|
new PropertyMetadata(false, (o, args) => { }));
|
2020-05-11 19:22:41 +02:00
|
|
|
|
|
|
|
|
|
public bool CanDragItems
|
|
|
|
|
{
|
|
|
|
|
get { return (bool)GetValue(CanDragItemsProperty); }
|
|
|
|
|
set { SetValue(CanDragItemsProperty, value); }
|
|
|
|
|
}
|
|
|
|
|
public static readonly DependencyProperty CanDragItemsProperty =
|
|
|
|
|
DependencyProperty.Register(
|
|
|
|
|
nameof(CanDragItems),
|
|
|
|
|
typeof(bool),
|
|
|
|
|
typeof(HamburgerMenuUserControl),
|
|
|
|
|
new PropertyMetadata(false, (o, args) => { }));
|
2020-05-05 16:59:49 +02:00
|
|
|
|
|
2020-04-28 15:20:47 +02:00
|
|
|
|
public ICommand ActionButtonCommand
|
2018-06-14 18:38:05 +02:00
|
|
|
|
{
|
2020-04-28 15:20:47 +02:00
|
|
|
|
get { return (ICommand)GetValue(ActionButtonCommandProperty); }
|
2020-04-21 13:33:15 +02:00
|
|
|
|
set { SetValue(ActionButtonCommandProperty, value); }
|
2018-06-14 18:38:05 +02:00
|
|
|
|
}
|
2020-04-21 13:33:15 +02:00
|
|
|
|
public static readonly DependencyProperty ActionButtonCommandProperty =
|
|
|
|
|
DependencyProperty.Register(
|
|
|
|
|
nameof(ActionButtonCommand),
|
2020-04-28 15:20:47 +02:00
|
|
|
|
typeof(ICommand),
|
2020-04-21 13:33:15 +02:00
|
|
|
|
typeof(HamburgerMenuUserControl),
|
|
|
|
|
new PropertyMetadata(null, (o, args) => { }));
|
2020-05-05 15:27:34 +02:00
|
|
|
|
|
2020-04-21 13:33:15 +02:00
|
|
|
|
public event EventHandler<SelectionChangedEventArgs> SelectionChanged;
|
2020-05-05 15:27:34 +02:00
|
|
|
|
|
|
|
|
|
public HamburgerMenuUserControl()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-21 13:33:15 +02:00
|
|
|
|
private void Selector_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
|
2018-06-14 18:38:05 +02:00
|
|
|
|
{
|
2020-04-21 13:33:15 +02:00
|
|
|
|
SelectionChanged?.Invoke(sender, e);
|
2018-06-14 18:38:05 +02:00
|
|
|
|
}
|
2020-05-04 20:56:19 +02:00
|
|
|
|
|
|
|
|
|
private void ToggleButton_OnUnchecked(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
var parent = Parent as FrameworkElement;
|
|
|
|
|
if (parent == null) return;
|
|
|
|
|
VisualStateManager.GoToState(this, parent.ActualWidth <= 640 ? "Hidden" : "Collapsed", true);
|
|
|
|
|
}
|
2020-05-05 15:27:34 +02:00
|
|
|
|
|
|
|
|
|
private void NewGroupTextBox_OnKeyDown(object sender, KeyRoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (e.Key != VirtualKey.Enter) return;
|
|
|
|
|
var textBox = sender as TextBoxWithButton;
|
|
|
|
|
ActionButtonCommand.Execute(textBox?.Text);
|
|
|
|
|
// Stop the event from triggering twice
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
}
|
2018-06-14 18:38:05 +02:00
|
|
|
|
}
|
|
|
|
|
}
|