简体   繁体   中英

Problem with InlineUIContainer

I have an Windows.Documents.InlineUIContainerin a RichTextBox, and sometimes it's font size of alignment change when I hit key combination such as Ctrl+Space. I couldn't find any place to handle these events and block them somehow. I don't want to block it in the RichTextBox. I am more looking for a way to block it only on the InlineUIContainer.

InlineUIContainer is a FrameworkContentElement, so it participates in all the normal event routing. So to block command routing need to do is use CommandManager.AddExecutedHandler (or equivalently AddHandler(CommandManager.ExecutedEvent) ) on the InlineUIContainer and mark the commands as 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;
}));

Alternatively the same handler can be added to your inline UI content (InlineUIContainer.Content) if it easier to do it that way.

Note that the above code blocks all EditingCommands, but you can block any other commands as desired.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM