I'd like to add tabs to my window when an item in the GridView is double-clicked. But the tab that will be added depends on the clicked item. Which way should I do this on WPF? I thought about RoutedEvents, but I don't know how to pass a parameter with it. Any suggestions?
Asked
Active
Viewed 5,371 times
2 Answers
6
This codeproject article covers using a new RoutedEvent
with a different argument type than just RoutedEventArgs
(rather far down, search for "Second using custom RoutedEventArgs"), though I wish WPF included a version of RoutedEventHandler
like the CLR's EventHandler<T> where T : EventArgs
so you didn't have to declare a new delegate every time.
The summary:
- Create a new type that subtypes RoutedEventArgs and has properties for your data.
- Make sure your RoutedEventArgs subtype implements the non-default constructors of RoutedEventArgs as those are needed for it to work.
- Declare a new delegate that matches this subtype.
- Use as you would any other custom event in your code (also covered in that link).

JustABill
- 1,562
- 15
- 20
-
you are free to create `RoutedEventHandler
` your self with a blink of an eye.. :) – ktutnik Jun 02 '12 at 23:40
0
Use commands rather than routed events:
Set a command for the clicked item and pass the clicked item's reference as the command's parameter using RelativeSource binding in the XAML.

Danny Varod
- 17,324
- 5
- 69
- 111