private void WindowLoaded(object sender, RoutedEventArgs e) { _mainViewModel = DataContext as MainViewModel; _mainViewModel.AnnoCanvas = annoCanvas; App.DpiScale = VisualTreeHelper.GetDpi(this); _instance = this; // add event handlers annoCanvas.OnCurrentObjectChanged += UpdateUIFromObject; annoCanvas.OnStatusMessageChanged += StatusMessageChanged; annoCanvas.OnLoadedFileChanged += LoadedFileChanged; annoCanvas.OnClipboardChanged += ClipboardChanged; DpiChanged += MainWindow_DpiChanged; foreach (MenuItem item in LanguageMenu.Items) { if (item.Header.ToString() == SelectedLanguage) { item.IsChecked = true; } } LoadSettings(); // add icons to the combobox comboBoxIcon.Items.Clear(); _noIconItem = new IconImage("None"); comboBoxIcon.Items.Add(_noIconItem); foreach (var icon in annoCanvas.Icons) { comboBoxIcon.Items.Add(icon.Value); } comboBoxIcon.SelectedIndex = 0; _mainViewModel.VersionValue = Constants.Version.ToString("0.0#", CultureInfo.InvariantCulture); _mainViewModel.FileVersionValue = CoreConstants.LayoutFileVersion.ToString("0.#", CultureInfo.InvariantCulture); // check for updates on startup CheckForUpdates(false);//just fire and forget // load color presets colorPicker.StandardColors.Clear(); //This is currently disabled colorPicker.ShowStandardColors = false; //try //{ // ColorPresetsLoader loader = new ColorPresetsLoader(); // var defaultScheme = loader.LoadDefaultScheme(); // foreach (var curPredefinedColor in defaultScheme.Colors.GroupBy(x => x.Color).Select(x => x.Key)) // { // //colorPicker.StandardColors.Add(new Xceed.Wpf.Toolkit.ColorItem(curPredefinedColor.Color, $"{curPredefinedColor.TargetTemplate}")); // colorPicker.StandardColors.Add(new Xceed.Wpf.Toolkit.ColorItem(curPredefinedColor, curPredefinedColor.ToHex())); // } //} //catch (Exception ex) //{ // MessageBox.Show(ex.Message, "Loading of the color presets failed"); //} // load presets BuildingPresets presets = annoCanvas.BuildingPresets; if (presets != null) { GroupBoxPresets.Header = string.Format("Building presets - loaded v{0}", presets.Version); _mainViewModel.PresetsVersionValue = presets.Version; _mainViewModel.PresetsTreeViewModel.ApplySelectedItem += PresetTreeViewModel_ApplySelectedItem; _mainViewModel.PresetsTreeViewModel.LoadItems(annoCanvas.BuildingPresets); //apply saved search before restoring state if (!string.IsNullOrWhiteSpace(Settings.Default.TreeViewSearchText)) { _mainViewModel.PresetsTreeViewModel.FilterText = Settings.Default.TreeViewSearchText; } if (!string.IsNullOrWhiteSpace(Settings.Default.PresetsTreeExpandedState)) { Dictionary <int, bool> savedTreeState = null; using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(Settings.Default.PresetsTreeExpandedState))) { savedTreeState = SerializationHelper.LoadFromStream <Dictionary <int, bool> >(ms); } _mainViewModel.PresetsTreeViewModel.SetCondensedTreeState(savedTreeState, Settings.Default.PresetsTreeLastVersion); } } else { GroupBoxPresets.Header = "Building presets - load failed"; } // load file given by argument if (!string.IsNullOrEmpty(App.FilenameArgument)) { annoCanvas.OpenFile(App.FilenameArgument); } }