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

InsertTextCommand parameter?

1 Answer 109 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Gunnar
Top achievements
Rank 1
Gunnar asked on 15 Mar 2011, 04:12 PM
I'm tying to extend the ribbon GUI with a new dropdown icon that allows users to select an item (text string) that should be inserted in the document at the current position. I assumed that the text to be inserted should be defined in the ConmmandParameter attribute, but nothing happens when I select the the entry.

<telerik:RadButton CornerRadius="3" Grid.Row="0"
IsBackgroundVisible="False" IsTabStop="False" 
telerik:RadRichTextBoxRibbonUI.RichTextCommand="{Binding Path=InsertTextCommand}"
CommandParameter="Text to be inserted" 
Text='Description'/>

Is it not possible to do this in XAML, do I have to create a Click event handler and call the command from there? If so - what should that event handler look like?

1 Answer, 1 is accepted

Sort by
0
Iva Toteva
Telerik team
answered on 17 Mar 2011, 06:35 PM
Hello Gunnar,

There is a slight difference with the approach you should adopt depending on the type of the button.
If the button is a RadRibbonButton (RadRibbonToggleButton, etc.), you can set the attached RadRichTextBoxRibbonUI.Command property, as in your code-snippet. With normal buttons and other RadButtons, you should set the button's Command property.
Do not forget to bind the DataContext property of the Button to the rich text box's Commands property in case it is not set on a parent of the Button in the visual tree.
In a nutshell, what you should do to have a RadButton insert text in a rich text box is:

<Grid x:Name="LayoutRoot" Background="White">
    <Grid.RowDefinitions>
        <RowDefinition Height="30" />
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>
    <telerik:RadButton Grid.Row="0" DataContext="{Binding ElementName=radRichTextBox1, Path=Commands}" IsTabStop="False"
                       Command="{Binding Path=InsertTextCommand}"
                       CommandParameter="Text to be inserted" Content="Insert Text"/>
    <telerik:RadRichTextBox Name="radRichTextBox1" Grid.Row="1" />
</Grid>

Regards,
Iva
the Telerik team
Tags
RichTextBox
Asked by
Gunnar
Top achievements
Rank 1
Answers by
Iva Toteva
Telerik team
Share this question
or