WPF Drag events Is Handled By Parent also - wpf

I am trying to implement form designer. In which I have a panel that contain another element and so on.Each dragable/dropable element will be an UserControl. I have created a common behavior for FrameworkElements and is applied for each dragable/dropable element. The problem is, when I drag over an element inside another element say a textBox Inside a panel, the dragover/dragenter events (drag events) are fired on both the parent and child. How to avoid firing events on the parent/container.

Related

Wpf parent child relationship

So i need to know that if a wpf window has got say 3 grids and we have a user control that we can drag. So when i drag it over the grids. Does the parent/child relationship changes every time i drag it over different grid?
I would say no, however that depends on your Drag/Drop implementation
Usually when dragging an item, you're actually just dragging a placeholder of that item in the Adorner Layer. The actual item may or may not get removed from the original parent. The item doesn't actually get added to the new parent until you release the mouse and the Drop method occurs.
When I implemented some custom drag/drop in the past, the item got removed from the parent control on Drag, and on Drop it got added to a new parent (either a valid drop target, or back to the original parent)

How can I make a control know if one of its children receives focus?

In Silverlight, controls can contain other controls.
I want to make my control know if any control further down the visual tree has received focus.
Is there a standard pattern for this and, if not, how could I do it?
UPDATE: I've found that the GotFocus event is bubbled up so a top level grid will see GotFocus fire each time a control within it or, crucially for me, within its children gets focus.
So now I'm wondering if this is always the case?

Navigating a WPF Tab Control from within a User Control?

My WPF application consists of a main window with a tab control which has a series of tab items, each hosting a user control.
I'd like one of the user controls to be able to trigger the application to change focus from the current tab to a different one.
Is there a way for the user control to trigger its tab control container to change to another tab item?
The WPF system provides the RoutedEvent. This special kind of event can be created to be catched by every element in the tree. With this way you can fire the event inside your user control, and catch it in the TabControl that will do everything you need. The tab control can catch the event cause of it lies in the element's tree of your window.
You can start from here:
http://msdn.microsoft.com/en-us/library/ms742806.aspx
You'll need a Bubble Event.
Hope this helps.
You can have a property that binds with SelectedItem property of TabControl.

Expand WPF Expander to bring contained element into view

I have an expander that has n contained elements (possibly other Expanders that also contain elements).
Now I want to programmatically bring a contained element into view - like with BringIntoView() for ScrollViewers. All Expanders that currently hide the element should expand.
My current idea is to subclass the Expander and make it react to an event that bubbles up from the contained element. But there may be a much easier way in WPF, right?
You can create an attached property to do that instead of subclassing the existing Expander class. This AP would be of type bool, and when sets to True on an expander register for the Expanded event. In the event handler, you can walk up the logical tree to grab the parent Expander and toogle is IsExpanded property.

How to Let WPF Control Animation Complete before Removing from Visual Tree

I have a scenario where I would like to animate a WPF control right before it is removed from the visual/logical trees. The control is custom, and the control style, including animations would be supplied by a designer (i.e. I don't know the details of what they will be at the time of writing the control code). I would like to provide routed events that allow the designer to trigger an animation right before the object is removed (e.g. the user is dragging the control with the mouse, and when the mouse button is released the control might fade away slowly instead of ubruptly being removed from the visual/logical tree). Is this possible just using routed events? Is it possible to detect when the animation has completed without requiring the designer to set a quirky dependency property or at the end of the animation to trigger the removal of the control? Using a dependency property would create a memory leak if the designer failed to set the property. Is there a better way?
Every storyboard has a Completed event that is called when the animation is done. You should handle that event and delete the control from that event. That way you can just start the animation when the mouse button is released.

Resources