Aug 18, 2009 at 1:35 PM
Edited Aug 19, 2009 at 3:05 AM
I test your code. In TextBlock, it looks fine, still not suitable to Datagrid.
I am sorry not to tell you that my project is Silverlight. So the class FrameworkPropertyMetadata can not be used in SL. I try to replace FrameworkPropertyMetadata of PropertyMetadata, it can be complied, but I think some function is blocked. So which action
shall I do something about FrameworkPropertyMetadata?
And also, about MouseEventArgs in your method OnEventRaised, I think it should be MouseButtonEventArgs, right?
Last, I test your code in DataGrid, debug on the method OnEventRaised, I find the parameter sender is a TextBlock, and when execute this code line as follow:
ICommand command = (ICommand)(sender as DependencyObject).
the command result in a null value. So no action to do finally. I try to seperate your code into 3 statements:
DependencyObject dp = sender as DependencyObject;
Object obj= dp.GetValue(SingleEventCommand.TheCommandToRunProperty);
ICommand command = obj as ICommand;
I find obj is null, it means DP TheCommandToRunProperty doesn't exist in sender, but when I change the 2nd statement as follow:
Object obj= dp.GetValue(SingleEventCommand.RoutedEventNameProperty);
My God, obj is not null, which means DP RoutedEventNameProperty exists in sender. Why these 2 DP are different, one is registered but the other one does not?