Beispiel #1
0
        private void TextBoxSearchPresetsKeyUp(object sender, KeyEventArgs e)
        {
            try
            {
                if (e.Key == Key.Escape)
                {
                    _mainWindowLocalization.TreeViewSearchText = string.Empty;
                    TextBoxSearchPresets.UpdateLayout();
                }

                if (_mainWindowLocalization.TreeViewSearchText.Length == 0)
                {
                    _treeViewSearch.Reset();
                    treeViewPresets.SetTreeViewState(_treeViewState);
                }
                else
                {
                    _treeViewSearch.Search(_mainWindowLocalization.TreeViewSearchText);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to execute search successfully.");
                App.WriteToErrorLog("Failed to execute search successfully", ex.Message, ex.StackTrace);
            }
        }
        private void TreeViewPresets_Loaded(object sender, RoutedEventArgs e)
        {
            //Intialise tree view and ensure that item containers are generated.
            _treeViewSearch = new TreeViewSearch <AnnoObject>(treeViewPresets, _ => _.Label)
            {
                MatchFullWordOnly = false,
                IsCaseSensitive   = false
            };
            _treeViewSearch.EnsureItemContainersGenerated();

            var isSearchState = false;

            if (!string.IsNullOrWhiteSpace(Settings.Default.TreeViewSearchText))
            {
                //Then apply the search **before** reloading state
                _treeViewSearch.Search(Settings.Default.TreeViewSearchText);
                isSearchState = true;
            }

            if (_treeViewState != null && _treeViewState.Count > 0)
            {
                try
                {
                    treeViewPresets.SetTreeViewState(_treeViewState);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Failed to restore previous preset menu settings.");
                    App.WriteToErrorLog("TreeView SetTreeViewState Error", ex.Message, ex.StackTrace);
                }
            }

            if (isSearchState)
            {
                //if the application was last closed in the middle of a search, set the previous state
                //to an empty value, so that we don't just expand the results of the search as the
                //previous state

                _treeViewState = new List <bool>();
            }
        }
        private void TextBoxSearchPresetsKeyUp(object sender, KeyEventArgs e)
        {
            var txt = sender as TextBox;

            try
            {
                if (txt.Text == "")
                {
                    _treeViewSearch.Reset();
                    treeViewPresets.SetTreeViewState(_treeViewState);
                }
                else
                {
                    _treeViewSearch.Search(txt.Text);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to execute search successfully.");
                App.WriteToErrorLog("Failed to execute search successfully", ex.Message, ex.StackTrace);
            }
        }