1
0
Fork 0
mirror of https://github.com/hawkeye-stan/msfs-popout-panel-manager.git synced 2024-10-16 14:10:45 +00:00
msfs-popout-panel-manager/MainApp/ViewModel/PanelConfigFieldViewModel.cs

55 lines
1.8 KiB
C#
Raw Permalink Normal View History

2023-07-12 22:41:31 +00:00
using MSFSPopoutPanelManager.DomainModel.Profile;
using MSFSPopoutPanelManager.Orchestration;
using Prism.Commands;
using System;
using System.Windows;
using System.Windows.Input;
namespace MSFSPopoutPanelManager.MainApp.ViewModel
{
public class PanelConfigFieldViewModel : BaseViewModel
{
2024-02-28 02:44:21 +00:00
private readonly PanelConfigurationOrchestrator _panelConfigurationOrchestrator;
2023-07-12 22:41:31 +00:00
public PanelConfig DataItem { get; set; }
public string BindingPath { get; set; }
public RoutedEvent SourceUpdatedEvent { get; set; }
public DelegateCommand<object> PlusMinusCommand { get; set; }
public ICommand DataUpdatedCommand { get; set; }
2024-02-28 02:44:21 +00:00
public PanelConfigFieldViewModel(SharedStorage sharedStorage, PanelConfigurationOrchestrator panelConfigurationOrchestrator) : base(sharedStorage)
2023-07-12 22:41:31 +00:00
{
2024-02-28 02:44:21 +00:00
_panelConfigurationOrchestrator = panelConfigurationOrchestrator;
2023-07-12 22:41:31 +00:00
PlusMinusCommand = new DelegateCommand<object>(OnPlusMinus);
DataUpdatedCommand = new DelegateCommand(OnDataUpdated);
}
private void OnPlusMinus(object param)
{
if (DataItem == null || BindingPath == null || param == null)
return;
var bindingPathProperty = typeof(PanelConfig).GetProperty(BindingPath);
2024-02-28 02:44:21 +00:00
if (bindingPathProperty == null)
return;
var value = Convert.ToInt32(bindingPathProperty.GetValue(DataItem, null));
bindingPathProperty.SetValue(DataItem, Convert.ToInt32(param) + value);
2023-07-12 22:41:31 +00:00
2024-02-28 02:44:21 +00:00
OnDataUpdated();
2023-07-12 22:41:31 +00:00
}
private void OnDataUpdated()
{
if (DataItem != null)
2024-02-28 02:44:21 +00:00
_panelConfigurationOrchestrator.PanelConfigPropertyUpdated(DataItem.PanelHandle, (PanelConfigPropertyName)Enum.Parse(typeof(PanelConfigPropertyName), BindingPath));
2023-07-12 22:41:31 +00:00
}
}
}