Good tutorials about routedEvent and customized routedEventArgs

Following is from http://social.msdn.microsoft.com/forums/en-US/wpf/thread/117fa340-c72e-4021-a1cf-a0f74352ceca/
====================================================
The following code works pretty well for me:
namespace MiscellaneousAnswers
{
public partial class RoutedEventHandlerProblem : Window
{
public RoutedEventHandlerProblem()
{
InitializeComponent();
TapCanvas canvas = new TapCanvas();
canvas.Background = Brushes.Red;
this.Content = canvas;
canvas.Tap += new TapRoutedEventHandler(canvas_Tap);
}

private void canvas_Tap(object sender, TapRoutedEventArgs e)
{
MessageBox.Show(e.Tap);
}
}

public class TapRoutedEventArgs : RoutedEventArgs
{
public String Tap
{
get;
set;
}

public TapRoutedEventArgs() : base() { }
public TapRoutedEventArgs(RoutedEvent routedEvent) : base(routedEvent) { }
public TapRoutedEventArgs(RoutedEvent routedEvent, Object source) : base(routedEvent, source) { }
}

public delegate void TapRoutedEventHandler(object sender, TapRoutedEventArgs e);
public class TapCanvas : Canvas
{
public static readonly RoutedEvent TapEvent = EventManager.RegisterRoutedEvent(
"Tap", RoutingStrategy.Bubble, typeof(TapRoutedEventHandler), typeof(TapCanvas));

public event TapRoutedEventHandler Tap
{
add { AddHandler(TapEvent, value); }
remove { RemoveHandler(TapEvent, value); }
}

protected virtual void RaiseTapEvent(String tap)
{
TapRoutedEventArgs newEventArgs = new TapRoutedEventArgs(TapCanvas.TapEvent);
newEventArgs.Tap = tap;
RaiseEvent(newEventArgs);
}

protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
{
this.RaiseTapEvent(e.OriginalSource.ToString());
}
}
}
Hope this helps

http://karlshifflett.wordpress.com/2007/11/07/routed-event-viewer/
http://roecode.wordpress.com/2008/01/10/wpf-usercontrols-as-a-modal-like-dialog/

Comments

Popular Posts