How can I make Silverlight controls invisible to mouse actions? - wpf

How can I get a UIElement to ignore mouse clicks on it and pass it through to the control behind it?
I have a 50% transparent UIElement which covers another element. When I attempt to click on the background element, the mouse click is captured by the foreground semi-transparent UIElement.

Set IsHitTestVisible=false

Related

Making UserControl transparent to mouse clicks

Is it possible for a UserControl to be transparent to mouse clicks/drags etc. and pass them to the control underneath it?

Highlighting control when mouse is over child control

I have a silverlight templated control that changes opacity when you hover it . However when user points cursor to its child control the effect wores off. I want to have the control highlighted also when the user hovers any child control. I've did the same thing in WinForms by overriding the WndProc method. Is there something similar in silverlight ?
Thanks
Sounds to me like you have not used the correct events to detect the hover, I suspect you are using MouseMove. Instead Use MouseEnter and MouseLeave events. An MouseEnter event will occur when the mouse moves over the control. You move the mouse over child controls and you will get no further events. Then when the mouse moves completely out of your control you will get MouseLeave.

allowing clicks on Button in ComboBoxItem when IsHitTestVisible is false

alt text http://img375.imageshack.us/img375/9830/combobox.png
Setting the IsHitTestVisible="false" has the effect of having the whole ComboBox's drop area unresponsive to clicks. The same goes for setting to true.
With a ComboBox I don't have to create any storyboard to make ComboBox animation like but I found this issue.
How can one make the ComboBoxItem area unclickable except for the button within?
Sounds like you should be creating a custom control that uses a popup window, that just looks like a combobox, however you can do what you wanted:
Put your buttons inside a grid, inside a single RadComboBoxItem
Set the grid background colour to 1% alpha so it is hit-test visible yet unseen
Add a Grid_MouseLeftButtonUp event handlern to the grid
In the handler set e.Handled to true so the mouse up is eaten
Make sure you close the combobox popup when you get your button presses.
Hope this helps.

How can I pass a mouse click to a parent control?

In a Silverlight 2 app, I am using Rectangles on a Canvas to draw a representation of data. I would like to have mouse clicks on the Rectangles be passed on to the control that owns the Canvas. I would also like to be able to show a tooltip with a summary of the data when the mouse is over a Rectangle.
So far I've only been able to achieve one item or the other. If I make the Rectangles have their IsHitTestVisible property = false, the tooltips don't work, but the owning control will receive the mouse clicks. If I set it to true, then tooltips do work, but the clicks don't get passed on.
Is there a way to have a Silverlight item be IsHitTestvisible = true, and pass on the mouse clicks?
I'm not sure why the tooltip and mouse left down / up is being linked, In SL3 the mouse left down / up will bubble unless it gets marked as handled by a routine / object. It sounds more like the event is not bubbling thru the parent controls. AFAIK SL2 does the same. (could be wrong on that one)
What is the visual tree from the outer parent to the inner rectangle?
Have Canvas pass a reference of itself to Rectangles when they're constructed. When a rectangle is clicked, call a method on Canvas.
Edit:
If Rectangles and Canvas are library classes, subclass them to add functionality you need.

Binding a Popup to another control's relative screen position

I'm writing an XBAP with a complex Popup (Canvas Z-index of 99 with a grid on it...) that I would like to "attach" to the button that opens it and follow that button around wherever it goes on the screen. For example, if the button is in a ListBox or an XamDataGrid I would like the popup to follow the button as it scrolls through. If it is beneath an Expander I want it to stay attached to the button when the expander forces it to move, etc.
Any Ideas?
When using a Popup, neither PlacementTarget nor CustomPopupPlacementCallback is used after the popup has originally appeared. So any use of these properties will not allow the popup to track the button as it moves.
Several ways occur to me of achieving what you desire:
Attach a custom Adorner to the button and put the popup inside it. Disadvantage: Popup is not connected to Button or surrounding elements, so it won't inherit properties & DataContext from them.
Attach a custom Adorner to the button. This adorner will get measure and arrange calls when the button moves relative to the AdornerLayer, allowing you to manually update the Popup position. As long as your AdornerDecorator doesn't move relative to your Window (eg if it is the direct child of the Window), you can easily detect the AdornerLayer being moved by monitoring changes to Window size. Disadvantage: Complex to code & get right.
Don't use a Popup at all. Instead wrap the button in a <Grid> alongside a <Canvas> with zero width and height and the desired position. Inside the <Canvas> add the UserControl for the popup with an appropriate ZIndex. It will extend past the edge f the Canvas, which is just fine in WPF. Instead of using a Popup control just control the visibility of the UserControl. Disadvantage: Will not really be totally on top of all other objects, can't extend off edge of window (may not be an issue for XBAP, though).
I'm not sure if it will auto-update for you or not, but the PlacementTarget property allows you to specify a control to position the popup relative to. If that doesn't work, then maybe CustomPopupPlacementCallback will do the trick?

Resources