This is a migrated thread and some comments may be shown as answers.

Bold, Italic, Underline ToggleButtons

2 Answers 649 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Erik
Top achievements
Rank 1
Erik asked on 03 Sep 2012, 03:47 PM
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 Answers, 1 is accepted

Sort by
0
Accepted
Petya
Telerik team
answered on 06 Sep 2012, 01:15 PM
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.

0
Erik
Top achievements
Rank 1
answered on 06 Sep 2012, 03:40 PM
Thanks, that worked perfectly.
Tags
RichTextBox
Asked by
Erik
Top achievements
Rank 1
Answers by
Petya
Telerik team
Erik
Top achievements
Rank 1
Share this question
or