Access to PreviewKeyDown event of richTextBox in userControl
我想知道如何访问
例如,我有用户控件,在这个用户控件中我只有一个richTextBox:
类似这样的:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | <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> |
我在 WPF 窗口中使用这个控件。
1 2 3 4 5 6 7 8 9 10 11 12 13 | <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> |
我想访问richTextBox的PreviewKeyDown,在这个事件上绑定一些方法并访问KeyEventArgs。
类似这样的:
1 2 3 4 5 6 7 | private void RichTextBoxInUserControl_PreviewKeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Enter ) { //... } } |
我注意到 Intellisense 没有在 Window 中启用
1 2 3 4 5 6 7 | <Spirit.Controls:RichTextBoxControl Name="RichTextBoxInUserControl" Background="Red" FontSize="13" Margin="4,4,4,4" Grid.Row="0" RichTextBox.PreviewKeyDown="RichTextBoxInUserControl_PreviewKeyDown"/> |
其中
中指定的