访问userControl中richTextBox的PreviewKeyDown事件
我想知道如何访问UserControl
中RichTextBox
的事件PreviewKeyDown
。
例如,我有用户控件,并且在此用户控件中我只有一个 richTextBox:
类似这样的内容:
<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 窗口中使用此控件。
<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。
像这样的事情:
private void RichTextBoxInUserControl_PreviewKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter )
{
//...
}
}
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:
Something like this:
<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.
Something like this:
private void RichTextBoxInUserControl_PreviewKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter )
{
//...
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我注意到 Intellisence 没有在 Window 中的
RichTextBox...
上识别,但您可以像这样订阅该事件,其中
RichTextBox
是工具包的名称:RichTextBox
在您的UserControl
中指定I noticed the Intellisence wasn't picking up on
RichTextBox...
in Window but you can subscribe to that event like thiswhere
RichTextBox
is the Name of thetoolkit:RichTextBox
specified in yourUserControl