示例#1
0
        public SnoopUI()
        {
            this.TreeService = TreeService.From(this.CurrentTreeType);

            this.filterCall = new DelayedCall(this.ProcessFilter, DispatcherPriority.Background);

            this.InitializeComponent();

            // wrap the following PresentationTraceSources.Refresh() call in a try/catch
            // sometimes a NullReferenceException occurs
            // due to empty <filter> elements in the app.config file of the app you are snooping
            // see the following for more info:
            // http://snoopwpf.codeplex.com/discussions/236503
            // http://snoopwpf.codeplex.com/workitem/6647
            try
            {
                PresentationTraceSources.Refresh();
                PresentationTraceSources.DataBindingSource.Switch.Level = SourceLevels.Error;
            }
            catch (NullReferenceException)
            {
                // swallow this exception since you can snoop just fine anyways.
            }

            this.CommandBindings.Add(new CommandBinding(IntrospectCommand, this.HandleIntrospection));
            this.CommandBindings.Add(new CommandBinding(RefreshCommand, this.HandleRefresh));
            this.CommandBindings.Add(new CommandBinding(HelpCommand, this.HandleHelp));

            this.CommandBindings.Add(new CommandBinding(InspectCommand, this.HandleInspect));

            this.CommandBindings.Add(new CommandBinding(SelectFocusCommand, this.HandleSelectFocus));
            this.CommandBindings.Add(new CommandBinding(SelectFocusScopeCommand, this.HandleSelectFocusScope));

            //NOTE: this is up here in the outer UI layer so ESC will clear any typed filter regardless of where the focus is
            // (i.e. focus on a selected item in the tree, not in the property list where the search box is hosted)
            this.CommandBindings.Add(new CommandBinding(ClearSearchFilterCommand, this.ClearSearchFilterHandler));

            this.CommandBindings.Add(new CommandBinding(CopyPropertyChangesCommand, this.CopyPropertyChangesHandler));

            InputManager.Current.PreProcessInput += this.HandlePreProcessInput;
            this.Tree.SelectedItemChanged        += this.HandleTreeSelectedItemChanged;

            // we can't catch the mouse wheel at the ZoomerControl level,
            // so we catch it here, and relay it to the ZoomerControl.
            this.MouseWheel += this.SnoopUI_MouseWheel;

            this.filterTimer = new DispatcherTimer
            {
                Interval = TimeSpan.FromSeconds(0.3)
            };
            this.filterTimer.Tick += (s, e) =>
            {
                this.EnqueueAfterSettingFilter();
                this.filterTimer.Stop();
            };
        }