1
0
Fork 0
mirror of https://github.com/hawkeye-stan/msfs-popout-panel-manager.git synced 2024-11-22 22:00:11 +00:00
msfs-popout-panel-manager/MainApp/UserControl/ProfileCard.xaml.cs

78 lines
2.7 KiB
C#
Raw Normal View History

2023-07-12 22:41:31 +00:00
using Microsoft.Extensions.DependencyInjection;
using MSFSPopoutPanelManager.DomainModel.Profile;
using MSFSPopoutPanelManager.MainApp.ViewModel;
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Input;
namespace MSFSPopoutPanelManager.MainApp
{
public partial class ProfileCard : UserControl
{
private ProfileCardViewModel? _viewModel;
public ProfileCard()
{
_viewModel = App.AppHost.Services.GetRequiredService<ProfileCardViewModel>();
InitializeComponent();
Loaded += (sender, e) => { DataContext = _viewModel; };
}
private void ToggleButtonEditProfileTitle_Click(object sender, RoutedEventArgs e)
{
ToggleButton? toggleButton = sender as ToggleButton;
if (toggleButton != null && toggleButton.IsChecked != null && (bool)toggleButton.IsChecked)
{
TxtBoxProfileTitle.Dispatcher.BeginInvoke(new Action(() => TxtBoxProfileTitle.Focus()));
TxtBoxProfileTitle.Dispatcher.BeginInvoke(new Action(() => TxtBoxProfileTitle.SelectAll()));
}
}
private void TxtBoxProfileTitle_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
ToggleButtonEditProfileTitle.IsChecked = false;
Keyboard.ClearFocus();
FocusManager.SetFocusedElement(FocusManager.GetFocusScope(rootCard), rootCard as IInputElement);
}
}
private void IncludeInGamePanel_TargetUpdated(object sender, DataTransferEventArgs e)
{
_viewModel.IncludeInGamePanelUpdatedCommand.Execute(null);
}
private void AddHudBar_TargetUpdated(object sender, DataTransferEventArgs e)
{
_viewModel.AddHudBarUpdatedCommand.Execute(null);
}
2023-07-23 05:13:23 +00:00
private void AddRefocusDisplay_TargetUpdated(object sender, DataTransferEventArgs e)
{
_viewModel.RefocusDisplayUpdatedCommand.Execute(null);
}
2023-07-12 22:41:31 +00:00
}
[ValueConversion(typeof(DateTime), typeof(String))]
public class StringToHudBarTypeConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return value.ToString().Replace("_", " ");
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
string data = value.ToString();
return Enum.Parse<HudBarType>(data.Replace(" ", "_"));
}
}
}