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 = 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 => 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") }); }