1
0
Fork 0
mirror of https://github.com/hawkeye-stan/msfs-popout-panel-manager.git synced 2024-11-29 09:10:09 +00:00
msfs-popout-panel-manager/WpfApp/AddProfileDialog.xaml.cs

64 lines
2.2 KiB
C#
Raw Normal View History

2022-01-27 13:40:04 +00:00
using MahApps.Metro.Controls;
2022-07-23 19:23:32 +00:00
using MSFSPopoutPanelManager.UserDataAgent;
2022-01-27 13:40:04 +00:00
using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Input;
namespace MSFSPopoutPanelManager.WpfApp
{
public partial class AddProfileDialog : MetroWindow
{
2022-07-23 19:23:32 +00:00
public List<Profile> UserProfiles { get; set; }
2022-01-27 13:40:04 +00:00
public int SelectedCopyProfileId { get; set; }
2022-07-23 19:23:32 +00:00
public AddProfileDialog(List<Profile> userProfiles)
2022-01-27 13:40:04 +00:00
{
InitializeComponent();
2022-07-23 19:23:32 +00:00
UserProfiles = userProfiles;
UserProfiles.Insert(0, new Profile() { ProfileId = -1 });
2022-01-27 13:40:04 +00:00
this.DataContext = this;
SelectedCopyProfileId = -1;
btnDialogOk.IsEnabled = false;
}
private void btnDialogOk_Click(object sender, RoutedEventArgs e)
{
this.DialogResult = true;
}
public string ProfileName
{
get { return txtProfileName.Text; }
}
private void Window_ContentRendered(object sender, EventArgs e)
{
txtProfileName.Focus();
}
private void Window_KeyDown(object sender, KeyEventArgs e)
{
bool isNumber = e.Key >= Key.D0 && e.Key <= Key.D9 || e.Key >= Key.NumPad0 && e.Key <= Key.NumPad9;
bool isLetter = e.Key >= Key.A && e.Key <= Key.Z || (e.Key >= Key.A && e.Key <= Key.Z && e.KeyboardDevice.Modifiers == ModifierKeys.Shift);
bool isCtrlA = e.Key == Key.A && e.KeyboardDevice.Modifiers == ModifierKeys.Control;
bool isCtrlV = e.Key == Key.V && e.KeyboardDevice.Modifiers == ModifierKeys.Control;
bool isBack = e.Key == Key.Back;
bool isLeftOrRight = e.Key == Key.Left || e.Key == Key.Right;
bool isEnterOrCancel = e.Key == Key.Enter || e.Key == Key.Escape;
if (isNumber || isLetter || isCtrlA || isCtrlV || isBack || isLeftOrRight || isEnterOrCancel)
e.Handled = false;
else
e.Handled = true;
}
private void txtProfileName_TextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e)
{
btnDialogOk.IsEnabled = txtProfileName.Text.Length > 0;
}
}
2022-06-30 23:53:08 +00:00
}