Bold, Italic, Underline ToggleButtons

3 posts, 1 answers
  1. Erik
    Erik avatar
    6 posts
    Member since:
    Jul 2012

    Posted 03 Sep 2012 Link to this post

    Hello,

    I followed the Getting Started tutorial here to create bold/italic/underline formatting toggle buttons for a WPF application: http://www.telerik.com/help/wpf/radrichtextbox-getting-started.html

    And they work, however there is a bug.

    If you have no text entered into the RichTextbox and click one of the buttons, it doesn't get highlighted. The text gets the correct formatting, however the button doesn't toggle.

    If you click in the middle of the text the buttons highlight correctly, it just seems to happen when the caret is at the end of the line (and outside a span maybe?).

    I'm not sure how to solve this.

    Thanks.
  2. Answer
    Petya
    Admin
    Petya avatar
    975 posts

    Posted 06 Sep 2012 Link to this post

    Hi Erik,

    In order to force your buttons to update when the ToggleState is changed, you'd have to subscribe to the ToggleStateChanged event as follows:

    public MainWindow()
    {
        InitializeComponent();
        this.radRichTextBox.Commands.ToggleBoldCommand.ToggleStateChanged += new EventHandler<Telerik.Windows.Documents.RichTextBoxCommands.StylePropertyChangedEventArgs<bool>>(ToggleBoldCommand_ToggleStateChanged);
        this.radRichTextBox.Commands.ToggleItalicCommand.ToggleStateChanged += new EventHandler<Telerik.Windows.Documents.RichTextBoxCommands.StylePropertyChangedEventArgs<bool>>(ToggleItalicCommand_ToggleStateChanged);
        this.radRichTextBox.Commands.ToggleUnderlineCommand.ToggleStateChanged += new EventHandler<Telerik.Windows.Documents.RichTextBoxCommands.StylePropertyChangedEventArgs<bool>>(ToggleUnderlineCommand_ToggleStateChanged);
    }
     
    void ToggleBoldCommand_ToggleStateChanged(object sender, Telerik.Windows.Documents.RichTextBoxCommands.StylePropertyChangedEventArgs<bool> e)
    {
        BoldButton.IsChecked = e.NewValue;
    }
     
    void ToggleUnderlineCommand_ToggleStateChanged(object sender, Telerik.Windows.Documents.RichTextBoxCommands.StylePropertyChangedEventArgs<bool> e)
    {
        UnderlineButton.IsChecked = e.NewValue;   
    }
     
    void ToggleItalicCommand_ToggleStateChanged(object sender, Telerik.Windows.Documents.RichTextBoxCommands.StylePropertyChangedEventArgs<bool> e)
    {
        ItalicButton.IsChecked = e.NewValue;
    }

    This should fix the behavior you are observing. If not, please do not hesitate to get back to us.

    Greetings,
    Petya
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. UI for WPF is Visual Studio 2017 Ready
  4. Erik
    Erik avatar
    6 posts
    Member since:
    Jul 2012

    Posted 06 Sep 2012 Link to this post

    Thanks, that worked perfectly.
Back to Top