92 lines
2.9 KiB
C#
92 lines
2.9 KiB
C#
using System.ComponentModel;
|
|
using System.Runtime.CompilerServices;
|
|
using System.Windows;
|
|
using System.Windows.Input;
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
using CommunityToolkit.Mvvm.Input;
|
|
|
|
namespace CtrEditor.PopUps
|
|
{
|
|
public partial class ScaleConfigWindow : Window
|
|
{
|
|
public ScaleConfigWindow(float currentScale)
|
|
{
|
|
InitializeComponent();
|
|
DataContext = new ScaleConfigViewModel(currentScale, this);
|
|
}
|
|
|
|
public float NewScale => ((ScaleConfigViewModel)DataContext).NewScale;
|
|
}
|
|
|
|
public partial class ScaleConfigViewModel : ObservableObject
|
|
{
|
|
private readonly ScaleConfigWindow _window;
|
|
|
|
[ObservableProperty]
|
|
private float currentScale;
|
|
|
|
[ObservableProperty]
|
|
private float newScale;
|
|
|
|
public ICommand SetPresetCommand { get; }
|
|
public ICommand AcceptCommand { get; }
|
|
public ICommand CancelCommand { get; }
|
|
|
|
public ScaleConfigViewModel(float currentScale, ScaleConfigWindow window)
|
|
{
|
|
_window = window;
|
|
CurrentScale = currentScale;
|
|
NewScale = currentScale;
|
|
|
|
SetPresetCommand = new RelayCommand<object>(SetPreset);
|
|
AcceptCommand = new RelayCommand(Accept, CanAccept);
|
|
CancelCommand = new RelayCommand(Cancel);
|
|
}
|
|
|
|
private void SetPreset(object parameter)
|
|
{
|
|
if (parameter != null && float.TryParse(parameter.ToString(),
|
|
System.Globalization.NumberStyles.Float,
|
|
System.Globalization.CultureInfo.InvariantCulture,
|
|
out float presetValue))
|
|
{
|
|
NewScale = presetValue;
|
|
}
|
|
}
|
|
|
|
private bool CanAccept()
|
|
{
|
|
return NewScale > 0; // Solo verificar que sea positivo
|
|
}
|
|
|
|
private void Accept()
|
|
{
|
|
if (NewScale <= 0)
|
|
{
|
|
MessageBox.Show("La escala debe ser un valor positivo mayor que cero.",
|
|
"Error de Validación",
|
|
MessageBoxButton.OK,
|
|
MessageBoxImage.Warning);
|
|
return;
|
|
}
|
|
|
|
// Debugging: mostrar mensaje para confirmar que se ejecuta
|
|
// MessageBox.Show($"Accept ejecutado con escala: {NewScale}", "Debug", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
|
|
_window.DialogResult = true;
|
|
// No necesitamos llamar Close() ya que establecer DialogResult automáticamente cierra la ventana
|
|
}
|
|
|
|
private void Cancel()
|
|
{
|
|
_window.DialogResult = false;
|
|
_window.Close();
|
|
}
|
|
|
|
partial void OnNewScaleChanged(float value)
|
|
{
|
|
// Forzar la re-evaluación del comando Accept cuando el valor cambia
|
|
CommandManager.InvalidateRequerySuggested();
|
|
}
|
|
}
|
|
} |