InlineUIContainer的问题

时间:2010-04-13 19:05:40

标签: c# .net wpf richtextbox inlineuicontainer

我在RichTextBox中有一个Windows.Documents.InlineUIContainer,有时当我按下Ctrl + Space等组合键时,它的字体大小会发生变化。我找不到任何地方来处理这些事件并以某种方式阻止它们。我不想在RichTextBox中阻止它。我更想找到一种方法来阻止它只在InlineUIContainer上。

1 个答案:

答案 0 :(得分:1)

InlineUIContainer是一个FrameworkContentElement,因此它参与所有正常的事件路由。因此,阻止命令路由需要做的是在InlineUIContainer上使用CommandManager.AddExecutedHandler(或等效AddHandler(CommandManager.ExecutedEvent))并将命令标记为Handled。

container.AddHandler(CommandManager.ExecutedEvent, new ExecutedRoutedEventHandler((obj, e) =>
{
  var command = e.Command as RoutedCommand;
  if(command!=null && command.OwnerType==typeof(EditingCommands))
    e.Handled = true;
}));

或者,如果更容易以这种方式执行,可以将相同的处理程序添加到内联UI内容(InlineUIContainer.Content)。

请注意,上面的代码会阻止所有EditingCommands,但您可以根据需要阻止任何其他命令。

相关问题