InsertTextCommand parameter?

2 posts, 0 answers
  1. Gunnar
    Gunnar avatar
    28 posts
    Member since:
    Aug 2009

    Posted 15 Mar 2011 Link to this post

    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?
  2. Iva Toteva
    Admin
    Iva Toteva avatar
    1319 posts

    Posted 17 Mar 2011 Link to this post

    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
Back to Top