public MainViewModel(XmlDatabase database) { if (database == null) throw new ArgumentNullException("database"); _database = database; Tabs = new ObservableCollection<TabViewModel>(); TabsView = (ListCollectionView) CollectionViewSource.GetDefaultView(Tabs); TabsView.SortDescriptions.Add(new SortDescription("Title", ListSortDirection.Ascending)); // Loading applications asynchronously using reactive extensions to reduce initial startup time. // TODO: Does this actually speed things up or is it loading all the sections before add doing // the subscribe?? _database.LoadTabs().ToObservable().Subscribe(tabModel => { TabViewModel tabViewModel = new TabViewModel(tabModel); Tabs.Add(tabViewModel); Configuration.AvailableTabs.Add(tabViewModel.Title); }, () => // OnComplete { Tabs.CollectionChanged += OnTabsChanged; // Expand the default tab when the application starts up. ExpandedTab = Tabs.SingleOrDefault(obj => obj.Title == Configuration.DefaultTab) ?? Tabs.FirstOrDefault(); }); Messenger.Default.Register<ApplicationMessage>(this, OnApplicationMessage); Messenger.Default.Register<TabMessage>(this, OnTabMessage); Messenger.Default.Register<TabToMainMessage>(this, OnTabToMainMessage); }
protected override void OnStartup(StartupEventArgs e) { Logger.Debug("OnStartUp"); InitializeComponent(); base.OnStartup(e); Application.Current.DispatcherUnhandledException += OnUnhandledException; // Load theme try { WpfHelper.LoadTheme(Configuration.CurrentTheme); } catch (Exception ex) { MessageBox.Show(String.Format("Failed to load theme {0}, {1}", Configuration.CurrentTheme, ex.Message), "Astounding Dock", MessageBoxButton.OK, MessageBoxImage.Error); } // Set default resources. Even if the theme fails to load, with these set the application should run fine. if (!this.Resources.Contains("WindowBackgroundBrush")) this.Resources.Add("WindowBackgroundBrush", new SolidColorBrush(Colors.Gray)); if (!this.Resources.Contains("TextBrush")) this.Resources.Add("TextBrush", new SolidColorBrush(Colors.Black)); // Register services RegisterServices(); // Load xml file XmlDatabase database = new XmlDatabase(Configuration.DatabaseFile); Application.Current.Exit += OnApplicationExit; // Opened the main window. MainViewModel viewModel = new MainViewModel(database); ServiceManager.GetService<IViewService>().OpenWindow(viewModel); }