Hi there
I am using a WPF c# application. I have a user control which contains a datagrid.
I am trying to send a public event from the user control , on a right mouse click.
Here is the created public event
public event MouseButtonEventHandler datagridMouseClick;
Next its supposed to be fired on this event handler of the datagrid:
private void dataGrid1_MouseDown(object sender, MouseButtonEventArgs e)
{
DependencyObject dep = (DependencyObject)e.OriginalSource;
while ((dep != null) &&
!(dep is DataGridCell) &&
!(dep is DataGridColumnHeader))
{
dep = VisualTreeHelper.GetParent(dep);
}
if (dep is DataGridCell)
{
cell = dep as DataGridCell;
while ((dep != null) && !(dep is DataGridRow))
{
dep = VisualTreeHelper.GetParent(dep);
}
row = dep as DataGridRow;
}
this.datagridMouseClick(sender, e);
}
OKK so this above is a code existing at an external object that i made, which has a datagrid, I will load this User Control into another project WPF and it will be named "search", the point of what i am doing here is to fire the PUBLIC event "datagridMouseClick" inside the eventhandler datagrid1_MouseDown (which is the handler of datagrid mouse click event) . Now i Fire the public event "datagridMouseClick" at this point in order to be able to listen to this event from the other project (which will contain this object "search") so that i will be able to handle the datagrid MouseClick event from there (not inside this object but from the other one).
The Other class initializes
public Window1(){
InitializeComponent();
search.datagridMouseClick += new MouseButtonEventHandler(search_datagridMouseClick);
search.datagridDoubleClick +=new RoutedEventHandler(search_datagridDoubleClick);
}
Ok so what i dont understand here is that theoratically datagridMouseClick should NEVER be null , since a handler is subscribed to it at this point of initialization before ANY possible click (which d be the only way to fire that event).
So,, the compiler never enters inside
search_datagridMouseClick
because the
datagridMouseClick
is null when fired,
I hope i was somewhat clear, i know it is something simple that i am missing. But i could use the help of someone more experienced here. Thank you for your patience, and feel free to ask if i was not clear.