Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > Avalon

Vista - Odd Routing behaviour: Bug or "feature"?

 
 
Old 10-27-2006   #1 (permalink)
Robin Davies


 
 

Odd Routing behaviour: Bug or "feature"?

Use case: mulitple input and output connector pin controls (hosted by
ItemsLists cotnrols) on a network node control, all implemented as WPF
templated controls. On the connector pins, I want to intercept and re-raise
mouse events as new events so that the top-level control can handle drag
events for making pin connections.

Environment:

..net Framework 3.0 September CTP, Orcas September CTP, Expression September
CTP, XP SP2. (would love to use RC1, but there isn't a version of orcas that
supports it yet).

The problem:

Handlers for the re-raised event (a newly declared event named
PinControl.ConnectorDragStartEvent) receive the event arguments for the
MouseLeftButtonDownEvent handler instead of the arguments passed to
RaiseEvent call for ConnectorDragStartEvent. The OriginalSource, Source, and
RoutedEvent properties of the arguments received in the
ConnectorDragStartEvent handler are those of the original
OnMouseLeftButtonDown call, instead of the supplied arguments.

My guess: there's inernal handling for routed events that does an equality
check based on time stamp and the result of GetType(). Shouldn't equality
comparison also include other properties like the RoutedEvent property?
Confusing, I suppose because the type of the arguments of the new event are
the same as those of the old.

Is this a bug or a feature? Am I doing something I shouldn't?


The code:
Code:
// Code to reraise a MouseLeftButtonDown event as
PinControl.ConnectorDragStartEvent
class PinControl: Control {
....
bool hasCapture = false;
protected override void
OnMouseLeftButtonDown(System.Windows.Input.MouseButtonEventArgs e)
{
e.Handled = true;
base.OnMouseLeftButtonDown(e);
if (this.CaptureMouse())
{
hasCapture = true;
RaiseConnectorDragStartEvent(e);
}
}
// Create a custom routed event by first registering a RoutedEventID
// This event uses the bubbling routing strategy
public static readonly RoutedEvent ConnectorDragStartEvent =
EventManager.RegisterRoutedEvent("ConnectorDragStart",
RoutingStrategy.Bubble, typeof(MouseButtonEventHandler),
typeof(PinControl));

// Provide CLR accessors for the event
public event MouseButtonEventHandler ConnectorDragStart
{
add { AddHandler(ConnectorDragStartEvent, value); }
remove { RemoveHandler(ConnectorDragStartEvent, value); }
}

// This method raises the ConnectorDragStart event
void RaiseConnectorDragStartEvent(MouseEventArgs args)
{
RoutedEventArgs newEventArgs = new MouseButtonEventArgs(
args.MouseDevice,
args.Timestamp,
MouseButton.Left,
args.StylusDevice);
newEventArgs.RoutedEvent = ConnectorDragStartEvent;
newEventArgs.Source = this;
RaiseEvent(newEventArgs);
}
....

// Code to handle PinControl.ConnectorDragStart
class NetworkNodeControl : Control
{
....
AddHandler(InputPinControl.ConnectorDragStartEvent,
new MouseButtonEventHandler(InputPin_OnDragStart));
....

private void InputPin_OnDragStart(object sender,
MouseButtonEventArgs args)
{
....
}
}
The issue:

I can successfully attach a handler for PinControl.ConnectorDragStartEvent
in the top-most control hosting the PinControl. I receive appropriate
notifications as well. But the event argument isn't the one that I passed to
RaiseEvent: it's the event arguments for MouseLeftButtonDown.



My System SpecsSystem Spec
 

Thread Tools


Similar Threads
Thread Forum
Re: Strange Icon Behaviour [0/1] "Desktopexample.nzb" yEnc (1/1) Vista file management
RequireFieldValidator and RangeValidator "strange" behaviour .NET General
Vista explorer missing feature? "filename only" select Vista file management
User Accounts and UAC Strange Behaviour, Users are not shown under "Manage another account" Vista account administration
Strange behaviour when using "Quotes" Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46