![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
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.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| 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)
{
....
}
}
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. |
![]() |
| 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 |