예제 #1
0
        public MainWindow()
        {
            InitializeComponent();

            ViewModel = new MainWindowViewModel();

            this.WhenActivated(disposables =>
            {
                this.Bind(ViewModel, vm => vm.FilterText, v => v.FilterTextBox.Text).DisposeWith(disposables);
                this.Bind(ViewModel, vm => vm.UseFuzzy, v => v.UseFuzzyToggleButton.IsChecked).DisposeWith(disposables);
                this.OneWayBind(ViewModel, vm => vm.GroupsView, v => v.GroupsListView.ItemsSource).DisposeWith(disposables);
                this.Bind(ViewModel, vm => vm.SelectedGroup, v => v.GroupsListView.SelectedItem).DisposeWith(disposables);
                this.OneWayBind(ViewModel, vm => vm.GroupsView.Count, v => v.CurrentShowCountRun.Text).DisposeWith(disposables);
                this.OneWayBind(ViewModel, vm => vm.Groups.Count, v => v.TotalCountRun.Text).DisposeWith(disposables);

                this.BindCommand(ViewModel, vm => vm.LoadGroups, v => v.RefreshButton).DisposeWith(disposables);

                Observable.Return(Unit.Default)
                .Where(_ => StateService.LastCacheUpdate < (DateTimeOffset.Now - TimeSpan.FromDays(5)))
                .InvokeCommand(ViewModel.LoadGroups)
                .DisposeWith(disposables);

                Observable.Return(Unit.Default)
                .Delay(TimeSpan.FromMilliseconds(100))
                .ObserveOnDispatcher()
                .Subscribe(x =>
                {
                    FilterTextBox.Focus();
                    FilterTextBox.SelectAll();
                })
                .DisposeWith(disposables);
            });
        }
 private void FilterTextBox_KeyDown(object sender, KeyEventArgs e)
 {
     if (e.KeyData == (Keys.Control | Keys.A))
     {
         FilterTextBox.SelectAll();
         e.Handled = e.SuppressKeyPress = true;
     }
 }
 private void TextBox_PreviewKeyDown(object sender, KeyEventArgs e)
 {
     _updateTimer.Stop();
     if (e.Key == Key.Enter)
     {
         ((AbstractEntityCollectionViewModelBase)DataContext).RefreshItems();
         FilterTextBox.SelectAll();
     }
     else if (e.Key == Key.Down)
     {
         MainGrid.BackgroundFocus();
     }
     else
     {
         _beforeText = FilterTextBox.Text;
         _updateTimer.Start();
     }
 }