Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > Avalon

Odd Routing behaviour: Bug or "feature"?

Closed Thread
 
Thread Tools Display Modes
Old 10-27-2006   #1 (permalink)
Robin Davies
Guest


 

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.


Closed Thread

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Vista explorer missing feature? "filename only" select Chewie Vista file management 2 01-27-2008 06:30 PM
User Accounts and UAC Strange Behaviour, Users are not shown under "Manage another account" lushdog Vista account administration 2 08-19-2007 01:12 PM
Troubles using "Turn Windows Feature On or Off" Vista Ultimate x64 DirtyAhjushi Vista installation & setup 0 08-10-2007 04:16 PM
Strange behaviour when using "Quotes" Mike Cook Vista General 4 07-04-2007 06:03 PM
Restore "Find exact phrase" search feature FrustratedVistaUser Vista file management 2 06-05-2007 03:53 PM








Vistax64.com 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 2005-2008

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 47 48 49 50