Acceso al evento PreviewKeyDown de richTextBox en userControl

I would like to know how can I get access to event PreviewKeyDown of RichTextBox in UserControl.

For example, I have user Control and in this user control I have only one richTextBox:

Algo como esto:

<UserControl x:Class="Spirit.Controls.RichTextBoxControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:toolkit="clr-namespace:Microsoft.Windows.Controls;assembly=WPFToolkit.Extended" 
             d:DesignHeight="300" d:DesignWidth="300">
    <Grid>
        <toolkit:RichTextBox Name="RichTextBox" 
                             Grid.Row="0" PreviewKeyDown="?">

       </toolkit:RichTextBox>
    </Grid>
</UserControl>

I use this control in WPF window.

<Window x:Class="WpfApplication2.Window2"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
        xmlns:Controls="clr-namespace:WpfApplication2.Controls" xmlns:WpfApplication2="clr-namespace:WpfApplication2" Title="Window2" Height="300" Width="300">
    <Grid>

        <Spirit.Controls:RichTextBoxControl Background="Red"
                                            FontSize="13"
                                            Margin="4,4,4,4" 
                                            Grid.Row="0" 
                                            Here I would like to acces to PreviewKeyDown of richTextBox/>
    </Grid>
</Window>

I would like have access to PreviewKeyDown of richTextBox, bind some method on this event and have access to KeyEventArgs.

Algo como esto:

   private void RichTextBoxInUserControl_PreviewKeyDown(object sender, KeyEventArgs e)
    {
        if (e.Key == Key.Enter )
        {
         //...
        }
    }

preguntado el 09 de enero de 11 a las 10:01

1 Respuestas

I noticed the Intellisence wasn't picking up on RichTextBox... in Window but you can subscribe to that event like this

<Spirit.Controls:RichTextBoxControl
               Name="RichTextBoxInUserControl"
               Background="Red"
               FontSize="13"
               Margin="4,4,4,4"
               Grid.Row="0"
               RichTextBox.PreviewKeyDown="RichTextBoxInUserControl_PreviewKeyDown"/>

dónde RichTextBox is the Name of the toolkit:RichTextBox especificado en su UserControl

Respondido el 09 de enero de 11 a las 18:01

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.