Esempio n. 1
0
        private void BindViewToViewModel()
        {
            // Append version number to caption (to save effort of producing an about screen)
            Title = string.Format("{0} ({1}) {2}", Assembly.GetExecutingAssembly().GetName().Name, Assembly.GetExecutingAssembly().GetName().Version, ServiceLocator.Instance.Get <ISessionManager>().Name);

            Preferences = ServiceLocator.Instance.Get <IUserPreferences>();
            ViewManager = ServiceLocator.Instance.Get <IViewManager>();

            // Maintaining column widths is proving difficult in Xaml alone, so
            // add an observer here and deal with it in code.
            if (Preferences is INotifyPropertyChanged)
            {
                (Preferences as INotifyPropertyChanged).PropertyChanged += PreferencesChanged;
            }

            DataContext = this;

            // When a new item is added, select the newest one.
            ViewManager.Viewers.CollectionChanged += ViewManagerChanged;

            //View-specific bindings
            var collapseIfZero = new CollapseIfZeroConverter();

            var standardHighlighters = new CollectionViewSource()
            {
                Source = Highlighters.Highlighters
            };

            standardHighlighters.View.Filter = c =>
            {
                if (c is IStandardDebuggingHighlighter)
                {
                    return(true);
                }
                return(false);
            };

            var customHighlighters = new CollectionViewSource()
            {
                Source = Highlighters.Highlighters
            };

            customHighlighters.View.Filter = c =>
            {
                if (c is IStandardDebuggingHighlighter)
                {
                    return(false);
                }
                return(true);
            };

            StandardHighlightersRibbonGroup.SetBinding(RibbonGroup.ItemsSourceProperty, new Binding()
            {
                Source = standardHighlighters
            });

            StandardHighlighterRibbonGroupOnTab.SetBinding(RibbonGroup.ItemsSourceProperty, new Binding()
            {
                Source = standardHighlighters
            });
            StandardHighlighterRibbonGroupOnTab.SetBinding(VisibilityProperty, new Binding()
            {
                Source    = standardHighlighters,
                Path      = new PropertyPath("Count"),
                Converter = collapseIfZero
            });
            CustomHighlighterRibbonGroupOnTab.SetBinding(RibbonGroup.ItemsSourceProperty, new Binding()
            {
                Source = customHighlighters
            });
            CustomHighlighterRibbonGroupOnTab.SetBinding(VisibilityProperty, new Binding()
            {
                Source    = customHighlighters,
                Path      = new PropertyPath("Count"),
                Converter = collapseIfZero
            });

            var standardFilters = new CollectionViewSource()
            {
                Source = Filters.Filters
            };

            standardFilters.View.Filter = c =>
            {
                if (c is IStandardDebuggingFilter)
                {
                    return(true);
                }
                return(false);
            };
            var customFilters = new CollectionViewSource()
            {
                Source = Filters.Filters
            };

            customFilters.View.Filter = c =>
            {
                if (c is IStandardDebuggingFilter)
                {
                    return(false);
                }
                return(true);
            };

            StandardFiltersRibbonGroup.SetBinding(RibbonGroup.ItemsSourceProperty, new Binding()
            {
                Source = standardFilters
            });

            StandardFiltersRibbonGroupOnTab.SetBinding(RibbonGroup.ItemsSourceProperty, new Binding()
            {
                Source = standardFilters
            });

            StandardFiltersRibbonGroupOnTab.SetBinding(VisibilityProperty, new Binding()
            {
                Source    = standardFilters,
                Path      = new PropertyPath("Count"),
                Converter = collapseIfZero
            });
            CustomFiltersRibbonGroupOnTab.SetBinding(RibbonGroup.ItemsSourceProperty, new Binding()
            {
                Source = customFilters
            });
            CustomFiltersRibbonGroupOnTab.SetBinding(VisibilityProperty, new Binding()
            {
                Source    = customFilters,
                Path      = new PropertyPath("Count"),
                Converter = collapseIfZero
            });

            var customExtractors = Extractors.Extractors;

            CustomExtractorsRibbonGroupOnTab.SetBinding(RibbonGroup.ItemsSourceProperty, new Binding()
            {
                Source = customExtractors
            });

            var customClassifyiers = ClassifyingService.Classifiers;

            CustomClassifiersRibbonGroupOnTab.SetBinding(RibbonGroup.ItemsSourceProperty, new Binding()
            {
                Source = customClassifyiers
            });

            //Bind search
            HighlightToggleButton.SetBinding(RibbonToggleButton.IsCheckedProperty, new Binding()
            {
                Source = Search,
                Path   = new PropertyPath("Enabled"),
                UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
            });
            FilterToggleButton.SetBinding(RibbonToggleButton.IsCheckedProperty, new Binding()
            {
                Source = SearchFilter,
                Path   = new PropertyPath("Enabled"),
                UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
            });
            ExtractToggleButton.SetBinding(RibbonToggleButton.IsCheckedProperty, new Binding()
            {
                Source = SearchExtractor,
                Path   = new PropertyPath("Enabled"),
                UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
            });

            if (Search.Enabled)
            {
                BindSearchToSearchHighlighter();
            }
            else if (SearchFilter.Enabled)
            {
                BindSearchToSearchFilter();
            }
            else if (SearchExtractor.Enabled)
            {
                BindSearchToSearchExtractor();
            }

            //Column view buttons
            ExceptionRibbonToggleButton.SetBinding(RibbonToggleButton.IsCheckedProperty, new Binding()
            {
                Source = Preferences,
                Path   = new PropertyPath("ShowExceptionColumn")
            });
            ThreadRibbonToggleButton.SetBinding(RibbonToggleButton.IsCheckedProperty, new Binding()
            {
                Source = Preferences,
                Path   = new PropertyPath("ShowThreadColumn")
            });
        }
Esempio n. 2
0
        private void BindViewToViewModel()
        {
            // Append version number to caption (to save effort of producing an about screen)
            Title =
                $"{Assembly.GetExecutingAssembly().GetName().Name} ({Assembly.GetExecutingAssembly().GetName().Version})"
                + $" {ServiceLocator.Instance.Get<ISessionManager>().Name}";

            // Preferences, if initialised, has come from persistence, so register current copy
            // otherwise, ask for one that will be shared.
            if (Preferences != null)
            {
                ServiceLocator.Instance.Register <IUserPreferences>(Preferences);
            }
            else
            {
                Preferences = ServiceLocator.Instance.Get <IUserPreferences>();
            }

            ViewManager = ServiceLocator.Instance.Get <IViewManager>();

            // Maintaining column widths is proving difficult in Xaml alone, so
            // add an observer here and deal with it in code.
            if (Preferences is INotifyPropertyChanged changed)
            {
                changed.PropertyChanged += PreferencesChanged;
            }

            DataContext = this;

            // When a new item is added, select the newest one.
            ViewManager.Viewers.CollectionChanged += ViewManagerChanged;

            // View-specific bindings
            var collapseIfZero = new CollapseIfZeroConverter();

            var standardHighlighters = new CollectionViewSource {
                Source = Highlighters.Highlighters
            };

            standardHighlighters.View.Filter = c => c is IStandardDebuggingHighlighter;

            var customHighlighters = new CollectionViewSource {
                Source = Highlighters.Highlighters
            };

            customHighlighters.View.Filter = c => !(c is IStandardDebuggingHighlighter);

            StandardHighlightersRibbonGroup.SetBinding(
                ItemsControl.ItemsSourceProperty,
                new Binding {
                Source = standardHighlighters
            });

            StandardHighlighterRibbonGroupOnTab.SetBinding(
                ItemsControl.ItemsSourceProperty,
                new Binding {
                Source = standardHighlighters
            });
            var collapsingStandardHighlightersBinding = new Binding
            {
                Source    = standardHighlighters,
                Path      = new PropertyPath("Count"),
                Converter = collapseIfZero,
            };

            StandardHighlighterRibbonGroupOnTab.SetBinding(VisibilityProperty, collapsingStandardHighlightersBinding);

            CustomHighlighterRibbonGroupOnTab.SetBinding(
                ItemsControl.ItemsSourceProperty,
                new Binding {
                Source = customHighlighters
            });

            var collapsingCustomHighlightersBinding = new Binding
            {
                Source    = customHighlighters,
                Path      = new PropertyPath("Count"),
                Converter = collapseIfZero,
            };

            CustomHighlighterRibbonGroupOnTab.SetBinding(VisibilityProperty, collapsingCustomHighlightersBinding);

            var standardFilters = new CollectionViewSource {
                Source = Filters.Filters
            };

            standardFilters.View.Filter = c => c is IStandardDebuggingFilter;

            var customFilters = new CollectionViewSource {
                Source = Filters.Filters
            };

            customFilters.View.Filter = c => !(c is IStandardDebuggingFilter);

            StandardFiltersRibbonGroup.SetBinding(
                ItemsControl.ItemsSourceProperty,
                new Binding {
                Source = standardFilters
            });

            StandardFiltersRibbonGroupOnTab.SetBinding(
                ItemsControl.ItemsSourceProperty,
                new Binding {
                Source = standardFilters
            });

            StandardFiltersRibbonGroupOnTab.SetBinding(
                VisibilityProperty,
                new Binding {
                Source = standardFilters, Path = new PropertyPath("Count"), Converter = collapseIfZero
            });
            CustomFiltersRibbonGroupOnTab.SetBinding(
                ItemsControl.ItemsSourceProperty,
                new Binding {
                Source = customFilters
            });
            CustomFiltersRibbonGroupOnTab.SetBinding(
                VisibilityProperty,
                new Binding {
                Source = customFilters, Path = new PropertyPath("Count"), Converter = collapseIfZero
            });

            var customExtractors = Extractors.Extractors;

            CustomExtractorsRibbonGroupOnTab.SetBinding(
                ItemsControl.ItemsSourceProperty,
                new Binding {
                Source = customExtractors
            });

            var customClassifyiers = ClassifyingService.Classifiers;

            CustomClassifiersRibbonGroupOnTab.SetBinding(
                ItemsControl.ItemsSourceProperty,
                new Binding {
                Source = customClassifyiers
            });

            BindToSearchElements();

            // Column view buttons
            ExceptionRibbonToggleButton.SetBinding(
                ToggleButton.IsCheckedProperty,
                new Binding {
                Source = Preferences, Path = new PropertyPath("ShowExceptionColumn")
            });
            ThreadRibbonToggleButton.SetBinding(
                ToggleButton.IsCheckedProperty,
                new Binding {
                Source = Preferences, Path = new PropertyPath("ShowThreadColumn")
            });
            SourceHostRibbonToggleButton.SetBinding(
                ToggleButton.IsCheckedProperty,
                new Binding {
                Source = Preferences, Path = new PropertyPath("ShowSourceColumn")
            });
            DebugSourceRibbonToggleButton.SetBinding(
                ToggleButton.IsCheckedProperty,
                new Binding {
                Source = Preferences, Path = new PropertyPath("ShowSourceInformationColumns")
            });
            ContextRibbonToggleButton.SetBinding(
                ToggleButton.IsCheckedProperty,
                new Binding {
                Source = Preferences, Path = new PropertyPath("ShowContextColumn")
            });
        }