47 lines
1.2 KiB
C#
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();
|
|
}
|
|
}
|
|
}
|