Tag: routedeventargs

使用RoutedEventArgs传递变量?

我有以下类,并希望将文本变量作为RoutedEventArgs传递。 public class CloseableTabItem : TabItem { String text; public CloseableTabItem() { //This style is defined in themes\generic.xaml DefaultStyleKeyProperty.OverrideMetadata(typeof(CloseableTabItem), new FrameworkPropertyMetadata(typeof(CloseableTabItem))); } public CloseableTabItem(String incomingText) { //This style is defined in themes\generic.xaml DefaultStyleKeyProperty.OverrideMetadata(typeof(CloseableTabItem), new FrameworkPropertyMetadata(typeof(CloseableTabItem))); text = incomingText; } public static readonly RoutedEvent CloseTabEvent = EventManager.RegisterRoutedEvent(“CloseTab”, RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(CloseableTabItem)); public event RoutedEventHandler CloseTab { add […]

为什么TextBlock不是Routed Event上的OriginalSource?

我正在为ListView元素显示上下文菜单。 上下文菜单附加到ListView的TextBlock ,如下所示。 正确显示上下文菜单,同时也会触发RoutedUIEvent。 问题是在Executed回调中, ExecutedRoutedEventArgs.OriginalSource是ListViewItem而不是TextBlock。 我尝试设置IsHitTestVisible属性以及Background (见下文),因为MSDN说OriginalSource是由命中测试决定的 请注意,我在ListView中使用GridView作为View。 这就是我想要获取TextBlock(获取列索引)的原因 主窗口 MainWindow.xaml.cs using System.Diagnostics; using System.Windows; using System.Windows.Input; namespace WpfApp1 { public class Data { public string Member1 { get; set; } } public partial class MainWindow : Window { public static RoutedCommand Test = new RoutedCommand(); public MainWindow() { InitializeComponent(); CommandBindings.Add(new CommandBinding(Test, (s, e) […]