public ContentEditor_Answers(DataStore dataStore, SelectButton control) { InitializeComponent(); data = dataStore; cont = control; ComboBox_FontSize.Text = "" + cont.FontSize; TB_MarginLeft.Text = "" + cont.Margin.Left; if (cont.Foreground is SolidColorBrush) { Rect_BackColor.Fill = cont.Foreground; } if (cont.FontWeight == FontWeights.Bold) { SButton_Bold.SetCheckedNoCall(true); } if (cont.FontStyle == FontStyles.Italic) { SButton_Italic.SetCheckedNoCall(true); } RB_WrongAns.IsChecked = !((Content_Answers)cont.Tag).ShowGood; try { ComboBox_FontName.Text = cont.FontFamily.ToString(); if (Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\GoodTeacher\\Temp\\")) { foreach (System.Windows.Media.FontFamily fm in Fonts.GetFontFamilies(new Uri(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\GoodTeacher\\Temp\\"))) { Label labelf = new Label(); labelf.Content = fm.ToString().Substring(3); labelf.FontFamily = fm; labelf.FontSize = 14; labelf.ToolTip = fm.ToString(); labelf.Foreground = new SolidColorBrush(Color.FromRgb(19, 87, 48)); ComboBox_FontName.Items.Add(labelf); } } foreach (System.Windows.Media.FontFamily fm in Fonts.SystemFontFamilies) { Label labelf = new Label(); labelf.Content = fm; labelf.FontFamily = fm; labelf.FontSize = 14; labelf.ToolTip = fm.ToString(); ComboBox_FontName.Items.Add(labelf); } } catch (Exception ex) { Debug.WriteLine("Font not found: " + ex); } }
private void Txt_SelectionChanged(object sender, RoutedEventArgs e) { try { if (txt.Selection.GetPropertyValue(FontSizeProperty) == DependencyProperty.UnsetValue) { ComboBox_FontSize.Text = "---"; } else { ComboBox_FontSize.Text = "" + txt.Selection.GetPropertyValue(FontSizeProperty); } ComboBox_FontName.Text = txt.Selection.GetPropertyValue(FontFamilyProperty).ToString(); if (((FontWeight)txt.Selection.GetPropertyValue(TextElement.FontWeightProperty)) == FontWeights.Bold) { SButton_Bold.SetChecked(true); } else { SButton_Bold.SetChecked(false); } if (((System.Windows.FontStyle)txt.Selection.GetPropertyValue(TextElement.FontStyleProperty)) == FontStyles.Italic) { SButton_Italic.SetChecked(true); } else { SButton_Italic.SetChecked(false); } FontVariants fv = (FontVariants)txt.Selection.GetPropertyValue(Typography.VariantsProperty); if (fv == FontVariants.Subscript) { SButton_SubScript.SetCheckedNoCall(true); SButton_SuperScript.SetCheckedNoCall(false); } else if (fv == FontVariants.Superscript) { SButton_SuperScript.SetCheckedNoCall(true); SButton_SubScript.SetCheckedNoCall(false); } else { SButton_SubScript.SetCheckedNoCall(false); SButton_SuperScript.SetCheckedNoCall(false); } TextDecorationCollection td = (TextDecorationCollection)txt.Selection.GetPropertyValue(Inline.TextDecorationsProperty); if (td == TextDecorations.Underline) { SButton_Underline.SetCheckedNoCall(true); SButton_Strikeline.SetCheckedNoCall(false); } else if (td == TextDecorations.Strikethrough) { SButton_Underline.SetCheckedNoCall(false); SButton_Strikeline.SetCheckedNoCall(true); } else { SButton_Underline.SetCheckedNoCall(false); SButton_Strikeline.SetCheckedNoCall(false); } TextAlignment textalign = (TextAlignment)txt.Selection.GetPropertyValue(Paragraph.TextAlignmentProperty); Button_LeftAlign.SetCheckedNoCall(false); Button_RightAlign.SetCheckedNoCall(false); Button_CenterAlign.SetCheckedNoCall(false); Button_JustifyAlign.SetCheckedNoCall(false); if (textalign == TextAlignment.Left) { Button_LeftAlign.SetCheckedNoCall(true); } else if (textalign == TextAlignment.Center) { Button_CenterAlign.SetCheckedNoCall(true); } else if (textalign == TextAlignment.Right) { Button_RightAlign.SetCheckedNoCall(true); } else if (textalign == TextAlignment.Justify) { Button_JustifyAlign.SetCheckedNoCall(true); } BackColor.Fill = (SolidColorBrush)txt.Selection.GetPropertyValue(Inline.BackgroundProperty); ForColor.Fill = (SolidColorBrush)txt.Selection.GetPropertyValue(Inline.ForegroundProperty); } catch (Exception ex) { Debug.WriteLine("Selection Changed: " + ex); } }
public void Load(Control control, DataStore data) { cont = control; try { ComboBox_FontName.Text = cont.FontFamily.ToString(); try { if (Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\GoodTeacher\\Temp\\")) { foreach (System.Windows.Media.FontFamily fm in Fonts.GetFontFamilies(new Uri(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\GoodTeacher\\Temp\\"))) { Debug.WriteLine(fm.ToString().Substring(3)); Debug.WriteLine("EXIST: " + data.FontManager.Exists(item => item.FontFamilyName == fm.ToString().Substring(3))); if (data.FontManager.Exists(item => item.FontFamilyName == fm.ToString().Substring(3))) { Label labelf = new Label(); labelf.Content = fm.ToString().Substring(3); labelf.FontFamily = fm; labelf.FontSize = 14; labelf.ToolTip = fm.ToString(); labelf.Foreground = new SolidColorBrush(Color.FromRgb(19, 87, 48)); ComboBox_FontName.Items.Add(labelf); } } } }catch (Exception ex) { Debug.WriteLine("!NotFoundFontFile: " + ex); } foreach (System.Windows.Media.FontFamily fm in Fonts.SystemFontFamilies) { Label labelf = new Label(); labelf.Content = fm; labelf.FontFamily = fm; labelf.FontSize = 14; labelf.ToolTip = fm.ToString(); ComboBox_FontName.Items.Add(labelf); } } catch (Exception ex) { Debug.WriteLine("Font not found: " + ex); } ComboBox_FontSize.Text = "" + cont.FontSize; if (cont.FontWeight == FontWeights.Bold) { SButton_Bold.SetCheckedNoCall(true); } else { SButton_Bold.SetCheckedNoCall(false); } if (cont.FontStyle == FontStyles.Italic) { SButton_Italic.SetCheckedNoCall(true); } else { SButton_Italic.SetCheckedNoCall(false); } if (cont.HorizontalContentAlignment == HorizontalAlignment.Left) { Button_LeftAlign.SetCheckedNoCall(true); } else if (cont.HorizontalContentAlignment == HorizontalAlignment.Center) { Button_CenterAlign.SetCheckedNoCall(true); } else if (cont.HorizontalContentAlignment == HorizontalAlignment.Right) { Button_RightAlign.SetCheckedNoCall(true); } if (cont.VerticalContentAlignment == VerticalAlignment.Top) { Button_VTopAlign.SetCheckedNoCall(true); } else if (cont.VerticalContentAlignment == VerticalAlignment.Center) { Button_VCenterAlign.SetCheckedNoCall(true); } else if (cont.VerticalContentAlignment == VerticalAlignment.Bottom) { Button_VBottomAlign.SetCheckedNoCall(true); } }