using Avalonia.Controls; using Avalonia.Input; using Lagerprogramm.Models; using Lagerprogramm.ViewModels; using System.Collections.Generic; using System.Threading.Tasks; namespace Lagerprogramm.Views; public partial class PartSearchDialog : Window { public Part? SelectedPart { get; private set; } public PartSearchDialog() { InitializeComponent(); KeyDown += OnKeyDown; } public async Task ShowPartSearch(IEnumerable parts, Window parent) { SelectedPart = null; var viewModel = new PartSearchDialogViewModel(parts); DataContext = viewModel; await ShowDialog(parent); return SelectedPart; } private void OnDoubleTapped(object? sender, TappedEventArgs e) { if (PartListBox.SelectedItem is Part part) { SelectedPart = part; Close(); } } private void OnKeyDown(object? sender, KeyEventArgs e) { if (e.Key == Key.Enter && PartListBox.SelectedItem is Part part) { SelectedPart = part; Close(); } } }