コード例 #1
0
 private void SelectButton_OnCheckChanged(object sender, bool IsChecked)
 {
     if (!txt.Selection.IsEmpty)
     {
         if (sender == SButton_Bold)
         {
             if (IsChecked)
             {
                 txt.Selection.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.Bold);
             }
             else
             {
                 txt.Selection.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.Normal);
             }
         }
         else if (sender == SButton_Italic)
         {
             if (IsChecked)
             {
                 txt.Selection.ApplyPropertyValue(TextElement.FontStyleProperty, FontStyles.Italic);
             }
             else
             {
                 txt.Selection.ApplyPropertyValue(TextElement.FontStyleProperty, FontStyles.Normal);
             }
         }
         else if (sender == SButton_Underline)
         {
             if (IsChecked)
             {
                 txt.Selection.ApplyPropertyValue(Inline.TextDecorationsProperty, TextDecorations.Underline);
                 SButton_Strikeline.SetCheckedNoCall(false);
             }
             else
             {
                 txt.Selection.ApplyPropertyValue(Inline.TextDecorationsProperty, null);
             }
         }
         else if (sender == SButton_Strikeline)
         {
             if (IsChecked)
             {
                 txt.Selection.ApplyPropertyValue(Inline.TextDecorationsProperty, TextDecorations.Strikethrough);
                 SButton_Underline.SetCheckedNoCall(false);
             }
             else
             {
                 txt.Selection.ApplyPropertyValue(Inline.TextDecorationsProperty, null);
             }
         }
         else if (sender == SButton_SubScript)
         {
             if (IsChecked)
             {
                 txt.Selection.ApplyPropertyValue(Typography.VariantsProperty, FontVariants.Subscript);
                 SButton_SuperScript.SetCheckedNoCall(false);
             }
             else
             {
                 txt.Selection.ApplyPropertyValue(Typography.VariantsProperty, FontVariants.Normal);
             }
         }
         else if (sender == SButton_SuperScript)
         {
             if (IsChecked)
             {
                 txt.Selection.ApplyPropertyValue(Typography.VariantsProperty, FontVariants.Superscript);
                 SButton_SubScript.SetCheckedNoCall(false);
             }
             else
             {
                 txt.Selection.ApplyPropertyValue(Typography.VariantsProperty, FontVariants.Normal);
             }
         }
     }
 }
コード例 #2
0
        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);
            }
        }