2024-09-17 14:42:07 +00:00
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using MSFSPopoutPanelManager.MainApp.ViewModel;
|
|
|
|
|
using System;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Windows;
|
2024-09-17 21:33:23 +00:00
|
|
|
|
using System.Windows.Controls;
|
2024-09-17 14:42:07 +00:00
|
|
|
|
using System.Windows.Input;
|
|
|
|
|
using System.Windows.Interop;
|
2024-09-17 21:33:23 +00:00
|
|
|
|
using System.Windows.Media;
|
2024-09-17 14:42:07 +00:00
|
|
|
|
|
|
|
|
|
namespace MSFSPopoutPanelManager.MainApp.AppWindow
|
|
|
|
|
{
|
|
|
|
|
public partial class SwitchWindow : Window
|
|
|
|
|
{
|
|
|
|
|
private readonly SwitchWindowViewModel _viewModel;
|
|
|
|
|
|
|
|
|
|
public SwitchWindow(Guid panelId, int initialWidth, int initialHeight)
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
if (DesignerProperties.GetIsInDesignMode(new DependencyObject()))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
_viewModel = App.AppHost.Services.GetRequiredService<SwitchWindowViewModel>();
|
|
|
|
|
_viewModel.PanelId = panelId;
|
|
|
|
|
|
|
|
|
|
Loaded += (_, _) =>
|
|
|
|
|
{
|
|
|
|
|
DataContext = _viewModel;
|
|
|
|
|
|
|
|
|
|
var window = Window.GetWindow(this);
|
|
|
|
|
if (window == null)
|
|
|
|
|
throw new ApplicationException("Unable to instantiate switchWindow window");
|
|
|
|
|
|
|
|
|
|
_viewModel.PanelConfig.PanelHandle = new WindowInteropHelper(window).Handle;
|
|
|
|
|
|
|
|
|
|
if (initialWidth == 0 && initialHeight == 0)
|
|
|
|
|
{
|
|
|
|
|
this.Width = 410;
|
2024-09-17 21:33:23 +00:00
|
|
|
|
this.Height = 60;
|
2024-09-17 14:42:07 +00:00
|
|
|
|
_viewModel.PanelConfig.Width = Convert.ToInt16(this.Width);
|
|
|
|
|
_viewModel.PanelConfig.Height = Convert.ToInt32(this.Height);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
this.Width = initialWidth;
|
|
|
|
|
this.Height = initialHeight;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
this.MouseLeftButtonDown += SwitchWindow_MouseLeftButtonDown;
|
|
|
|
|
this.Topmost = true;
|
2024-09-17 21:33:23 +00:00
|
|
|
|
|
|
|
|
|
if (_viewModel.ProfileData.ActiveProfile.ProfileSetting.SwitchWindowConfig.Panels != null)
|
|
|
|
|
{
|
|
|
|
|
var style = Application.Current.TryFindResource("MaterialDesignOutlinedButton") as Style;
|
|
|
|
|
|
|
|
|
|
WrapPanelCustomButtons.Children.Clear();
|
|
|
|
|
|
|
|
|
|
foreach (var panel in _viewModel.ProfileData.ActiveProfile.ProfileSetting.SwitchWindowConfig.Panels)
|
|
|
|
|
{
|
|
|
|
|
WrapPanelCustomButtons.Children.Add(new Button()
|
|
|
|
|
{
|
|
|
|
|
Height = 45,
|
|
|
|
|
Margin = new Thickness(5, 5, 5, 5),
|
|
|
|
|
Content = panel.DisplayName,
|
|
|
|
|
Foreground = new SolidColorBrush(Colors.White),
|
|
|
|
|
FontSize = 28,
|
|
|
|
|
Style = style,
|
|
|
|
|
Command = _viewModel.ButtonCommand,
|
|
|
|
|
CommandParameter = panel.PanelCaption
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-09-17 14:42:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SwitchWindow_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
DragMove();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void BtnClose_Click(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
this.Close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|