public DrawBoardViewModel() { CanvasSize canvasSize1 = new CanvasSize("100%", 1.0); CanvasSize canvasSize2 = new CanvasSize("125%", 1.25); CanvasSize canvasSize3 = new CanvasSize("150%", 1.5); CnavasSizeList.Add(canvasSize1); CnavasSizeList.Add(canvasSize2); CnavasSizeList.Add(canvasSize3); List <MyFontFamily> myFontList = new List <MyFontFamily>(); myFontList = GetAllFonts(); fonts = new ObservableCollection <MyFontFamily>(myFontList); fontSizeList = new ObservableCollection <int>() { 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 26, 28, 32, 36, 42, 46, 50 }; SelectedFontSize = fontSizeList.ToList().Find(p => p == 16); foregrounds = new ObservableCollection <string>() { "White", "Black", "Gray", "Green", "Blue", "Yellow", "Orange" }; selectedColor = foregrounds.First(); selectedFontFamily = myFontList.Find(p => p.FontName == "微软雅黑"); var allColors = GetAllColors(); lineBrushes = new ObservableCollection <string>(allColors); selectedLineColor = allColors.Find(p => p == "Red"); }
private List <MyFontFamily> GetAllFonts() { List <MyFontFamily> myFontList = new List <MyFontFamily>(); var fontCollection = Fonts.GetFontFamilies(@"c:\Windows\Fonts"); if (fontCollection != null) { foreach (var item in fontCollection) { var name = string.Empty; var languageItem = System.Windows.Markup.XmlLanguage.GetLanguage("zh-cn"); if (item.FamilyNames.Keys.Contains(languageItem)) { name = item.FamilyNames[languageItem]; } else { var enLanguageItem = System.Windows.Markup.XmlLanguage.GetLanguage("en-us"); if (item.FamilyNames.Keys.Contains(enLanguageItem)) { name = item.FamilyNames[enLanguageItem]; } } var myFontItem = new MyFontFamily() { FontFamilyEntity = item, FontName = name }; myFontList.Add(myFontItem); } } return(myFontList); }