views:

26

answers:

1

Hi

I have nested listview in wpf. user can double click the listitem and open the item document. so I have ListView1_MouseDoubleClick and child listview 2 ListView2_MouseDoubleClick

but when user double click listview2 item , the listview1 also received mousedoubleclick event.

so... inorder to fix this problem as far as I know there are two solutions

A) -- add a bool flag and set to false

code:
Listview2_mousedoubleclick()
{
    flag=true;
}

ListView1_mousedoubleclick()
{
    if (flag==true) { flag=false;return}
}

B) -- Used VisualTreeHelper and analysis e.Source to find which one should response...

question: which way is better?

+1  A: 

I think you are seeing a routed event bubbling up the control tree here. You may set a Handled property in the event itself when you handle it to stop it from bubbling further up. I don't know the exact specifics right now as my WPF knowledge is a bit rusty but there was a way to stop such an event handling chain at a certain point you control.

Joey
Yes! my just want to stop event handing chain. I have try e.Handled = true; but the ListView1 still able to receive mouse click event..//REF: private void ListView2_MouseDoubleClick(object sender, MouseButtonEventArgs e)
ariso