Files
lagerprogramm/Views/DeductionSearchDialog.axaml.cs
joel.leirer fb1f90a9ca Added Slop
2026-08-25 17:14:54 +02:00

47 lines
1.2 KiB
C#

using Avalonia.Controls;
using Avalonia.Input;
using Lagerprogramm.Models;
using Lagerprogramm.ViewModels;
using System.Collections.ObjectModel;
using System.Threading.Tasks;
namespace Lagerprogramm.Views;
public partial class DeductionSearchDialog : Window
{
public Deduction? SelectedDeduction { get; private set; }
public DeductionSearchDialog()
{
InitializeComponent();
KeyDown += OnKeyDown;
}
public async Task<Deduction?> ShowDeductionSearch(ObservableCollection<Deduction> deductions, Window parent)
{
SelectedDeduction = null;
var viewModel = new DeductionSearchDialogViewModel(deductions);
DataContext = viewModel;
await ShowDialog(parent);
return SelectedDeduction;
}
private void OnDoubleTapped(object? sender, TappedEventArgs e)
{
if (DeductionListBox.SelectedItem is Deduction deduction)
{
SelectedDeduction = deduction;
Close();
}
}
private void OnKeyDown(object? sender, KeyEventArgs e)
{
if (e.Key == Key.Enter && DeductionListBox.SelectedItem is Deduction deduction)
{
SelectedDeduction = deduction;
Close();
}
}
}