index > Windows Presentation Foundation ("Avalon") > InlineUIContainers not firing any events in the RichTextBox

InlineUIContainers not firing any events in the RichTextBox

Hi,

Up until the June CTP, I was able to trap events from elements inside a InlineUIContainer, e.g.

// Wherever you create the InlineUIContainer

Canvas can = new Canvas();

can.Width = 80.0;

can.Height = 20.0;

can.Background = Brushes.Blue;

can.PrevewMouseMove += ........

InlineUIContainer uiCon = new InlineUIContainer(can);

This used to work find as any delegate added to the elements (even though the InlineUIContainer was "Disabled") would fire. Now it doesn't. Can someone please help me?

Thank you very much,

Jaco

CodeDjinn

I would expect the behavior you're seeing is in the context of a RichTextBox. In earlier builds, it was possible to enable UIElements embedded in RichTextBoxes, but in recent builds (and in RTM), embedded UIElements are always disabled when placed inside RichTextBoxes. And when disabled, they don't receive UI events.

You could work around by placing the FlowDocument in a FlowDocumentReader. However, with this workaround the user won't be able to edit the content.

Another idea is to attach your PreviewMouseDown (or whatever) handler to the RichTextBox itself, then use hit testing (RichTextBox.GetPositionFromPoint) to detect a mouse move over an element you care about.

Ben

Ben Westbrook - MSFT

The thing is, the InlineUIContainers was disabled in the Beta 2 release, and yet, with the elements disabled I was able to trap the events from the elements contained in a InlineUIContainer.

Well if there really isn't a different way, can you maby supply a little sample showing the hit testing scenario?

Thank you very much,

Jaco

CodeDjinn

I don't have an explanation for the beta 2 behavior.

With the latest bits, you should be able to do something like this. This is off the cuff code, no guarantee it's bug free .

void OnMouseMoveListener(object sender, MouseEventArgs e)

{

TextPointer position = richTextBox.GetPositionFromPoint(e.GetPosition(richTextBox), false /* snapToText */);

if (position == null)

{

return;

}

UIElement uiElement = position.GetAdjacentElement(position.LogicalDirection) as UIElement;

if (uiElement != null && IsInterestingElement(uiElement))

{

DoSomething();

}

}

The basic idea is that position will be adjacent to whatever the mouse is over. Its LogicalDirection property tells you if the content hit precedes or follows the pointer.

Ben

Ben Westbrook - MSFT

That is very strange, so is there any reason why the control inside the InlineUIContainer can't be disabled, but still fire events? (I know its a bit over reaching, but I have to try).

So other than the example you suggested, there is no other way? (I am not ungrateful, I appreciate all the help, but there is a certain distaste of trapping events like the way described, it is way to error prone)

Thank you very much,

Jaco

CodeDjinn

It's a feature of disabled controls that they don't receive events. Otherwise the control owners would have to add property checks to their decision tree.

The fundamental problem here is that RichTextBox has a very poor story for embedded UIElements, or custom TextElements. We didn't have the resources to make this work in V1, so you're left with distasteful workarounds like what I suggested. You'll run into additional problems, in particular clipboard operations like cut and paste drop all UIElements other than Image. You can work around that by handling cut and paste yourself, but again it's a very poor story.

Ben

Ben Westbrook - MSFT

O well, thank you very much then. If there is no other way, I guess the workaround is much better than having no solution at all! :)

I thank you for all you're help.

Jaco

CodeDjinn
reply 7

You can use google to search for other answers

 

More Articles

• Where does the teapotModel come from?
• Sharing ControlTemplate
• PageFunction Base Class
• Strings, Integers, and Colors in Resources?
• Can i pass URL query strings from one xaml to other.
• Conversion Validation order
• GroupStyle and WrapPanel
• FormsAuthenticationCookie in WPF
• How to pass parameters to a DataBinding in XAML? - I want (need) ...
• XamlParseException Line1 Postion 9????
Bookmark and Share
Welcome to Bokebb   New Update  
 

New Articles

• Glyphs.FontUri and installed font files
• Poor performance caused by Frame
• IRC Help Channel!
• Set Up project is not working properly
• ToolBar - OverflowGrid style?
• PreviewMouseMove event of Canvas not rec
• CanExecute handler is called, Executed h
• Getting started with video and animated 3D
• window allways on top
• Cannot set Name attribute value 'Tab1' o
• MarkupExtension to Connect WPF to CAB Se
• Disable page input during asynchronous p
• dev setup for Vista RC2?
• Is WPF right for my app?
• Get all bindings on a page?

Hot Articles

• Data bound ListView, Subscripts for Chem
• UpdateSource() on each BindingExpression?
• Databinding dropped in composite control
• SpeedRatio BUG?? - OK I'll Try this again
• Layout Transformation
• What is System.Windows.Documents.Glyphs?
• Is it possible to do a MasterDetail Bind
• Removing (all) items in a databound List
• Select a cell in a ListView
• How To: Attach event handler to element
• Apply 2 or more styles to an element
• Styling Brushes
• When to use windows browser app?
• how to generate xps document with conten
• Data binding: bind DrawingBrush to Recta

Recommend Articles

• How to create an instance of ObservableC
• Change the image dynamically from the St
• Timeline Assumptions - Vista release as
• New XBAP and Code @ xamlXaml.com: Scroll
• MouseEnter + grid row + animation problem
• ppt file can't show on server
• How to prevent duplicate items in Listvi
• WPF Bug or What????
• How to auto-size ListView column headers
• how to stop elements from being created?
• Will TreeView.ChangeSelection() be virtu
• Load image into richtext box
• TreeView with label editing
• Textbox default contextmenu Style
• Binding Combobox to TexBlock.VerticalAli