Beispiel #1
0
 private void Button_Align_OnCheckChanged(object sender, bool IsChecked)
 {
     if (sender == Button_LeftAlign)
     {
         txt.Selection.ApplyPropertyValue(Paragraph.TextAlignmentProperty, TextAlignment.Left);
         Button_LeftAlign.SetCheckedNoCall(true);
         Button_RightAlign.SetCheckedNoCall(false);
         Button_CenterAlign.SetCheckedNoCall(false);
         Button_JustifyAlign.SetCheckedNoCall(false);
     }
     else if (sender == Button_CenterAlign)
     {
         txt.Selection.ApplyPropertyValue(Paragraph.TextAlignmentProperty, TextAlignment.Center);
         Button_RightAlign.SetCheckedNoCall(false);
         Button_JustifyAlign.SetCheckedNoCall(false);
         Button_LeftAlign.SetCheckedNoCall(false);
         Button_CenterAlign.SetCheckedNoCall(true);
     }
     else if (sender == Button_RightAlign)
     {
         txt.Selection.ApplyPropertyValue(Paragraph.TextAlignmentProperty, TextAlignment.Right);
         Button_CenterAlign.SetCheckedNoCall(false);
         Button_JustifyAlign.SetCheckedNoCall(false);
         Button_LeftAlign.SetCheckedNoCall(false);
         Button_RightAlign.SetCheckedNoCall(true);
     }
     else if (sender == Button_JustifyAlign)
     {
         txt.Selection.ApplyPropertyValue(Paragraph.TextAlignmentProperty, TextAlignment.Justify);
         Button_RightAlign.SetCheckedNoCall(false);
         Button_CenterAlign.SetCheckedNoCall(false);
         Button_LeftAlign.SetCheckedNoCall(false);
         Button_JustifyAlign.SetCheckedNoCall(true);
     }
 }
Beispiel #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);
            }
        }