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 ShowDeductionSearch(ObservableCollection 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(); } } }