using CeramicProjectTool.Model; using CeramicProjectTool.ViewModel; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; namespace CeramicProjectTool.Pages { /// /// PermissionConfigPage.xaml 的交互逻辑 /// public partial class PermissionConfigPage : Page { private PermissonConfigViewModel viewModel; public PermissionConfigPage() { InitializeComponent(); viewModel = new PermissonConfigViewModel(); this.DataContext = viewModel; } private void Page_Loaded(object sender, RoutedEventArgs e) { LoadData(); } private void LoadData(string searchText = "") { Task> task; if (string.IsNullOrWhiteSpace(searchText)) { task = viewModel.GetPermissons(); } else { task = viewModel.GetPermissons(searchText); } task.ContinueWith((t) => { permissonData.Dispatcher.Invoke(() => { permissonData.ItemsSource = t.Result; }); }); } private void searchBox_TextInput(object sender, TextCompositionEventArgs e) { } private void searchBox_KeyDown(object sender, KeyEventArgs e) { var enterKey = Key.Enter; if (e.Key == enterKey) { var searchText = searchBox.Text; if (!string.IsNullOrWhiteSpace(searchText)) { LoadData(searchText); } } } } }