1
0
Fork 0
mirror of https://github.com/hawkeye-stan/msfs-popout-panel-manager.git synced 2024-11-25 15:20:10 +00:00
msfs-popout-panel-manager/MainApp/AppUserControl/DynamicLodPreference.xaml.cs

93 lines
2.5 KiB
C#
Raw Permalink Normal View History

2024-03-14 22:50:32 +00:00
using MSFSPopoutPanelManager.MainApp.ViewModel;
2024-02-28 02:44:21 +00:00
using System.ComponentModel;
using System.Globalization;
using System.Windows;
using System.Windows.Controls;
2024-03-14 22:50:32 +00:00
using System.Windows.Input;
2024-02-28 02:44:21 +00:00
namespace MSFSPopoutPanelManager.MainApp.AppUserControl
{
public partial class DynamicLodPreference
{
public DynamicLodPreference()
{
if (DesignerProperties.GetIsInDesignMode(new DependencyObject()))
{
InitializeComponent();
return;
}
2024-03-14 22:50:32 +00:00
2024-02-28 02:44:21 +00:00
Loaded += (_, _) =>
{
InitializeComponent();
var dataContext = DataContext as ApplicationViewModel;
};
}
2024-03-14 22:50:32 +00:00
private void TxtBox_NumbersOnly(object sender, TextCompositionEventArgs e)
2024-02-28 02:44:21 +00:00
{
2024-03-14 22:50:32 +00:00
e.Handled = !(int.TryParse(e.Text, out _) || (e.Text.Trim() == "-"));
2024-02-28 02:44:21 +00:00
}
}
2024-03-14 22:50:32 +00:00
2024-02-28 02:44:21 +00:00
public class AglValidationRule : ValidationRule
{
private const int MIN = -2000;
private const int MAX = 99999;
public override ValidationResult Validate(object value, CultureInfo cultureInfo)
{
var agl = 0;
try
{
var valueString = value as string;
if (valueString?.Length > 0)
agl = int.Parse(valueString);
}
catch
{
return new ValidationResult(false, "AGL must be a number.");
}
if (agl is < MIN or > MAX)
{
return new ValidationResult(false,
$"AGL must be in the range: {MIN} - {MAX}.");
}
return ValidationResult.ValidResult;
}
}
public class LodValidationRule : ValidationRule
{
private const int MIN = 0;
private const int MAX = 400;
public override ValidationResult Validate(object value, CultureInfo cultureInfo)
{
var lod = 0;
try
{
var valueString = value as string;
if (valueString?.Length > 0)
lod = int.Parse(valueString);
}
catch
{
return new ValidationResult(false, "LOD must be a number.");
}
if (lod is < MIN or > MAX)
{
return new ValidationResult(false,
$"LOD must be in the range: {MIN} - {MAX}.");
}
return ValidationResult.ValidResult;
}
}
}