Listbox double click problemsOK so I have done the following to allow my listbox items (which use a datatemplate and are bound to an ObservableCollection in my code behind) to have a double click event:<br/><br/> <pre lang=x-xml>&lt;ListBox.ItemContainerStyle&gt; &lt;Style TargetType=&quot;ListBoxItem&quot;&gt; &lt;EventSetter Event=&quot;MouseDoubleClick&quot; Handler=&quot;User_DoubleClick&quot;/&gt; &lt;Setter Property=&quot;Template&quot; Value=&quot;{DynamicResource ListBoxItemHighlightCT}&quot;/&gt; &lt;/Style&gt; &lt;/ListBox.ItemContainerStyle&gt;</pre> So then my User_DoubleClick sub basically just does a few things and then needs to show a new window. The problem is that although it shows this new window, the window never has focus and so is hidden behind the main window that has the listbox on it. Im assuming the reason for this is because after the double click event is fired it runs the code in my User_DoubleClick sub and then returns focus to the main window.<br/><br/>The only 'solution' I have at the moment is to just use a timer in the Loaded event of the new window so that after say 500 ms it just uses Me.Activate() to bring itself into focus but needless to say thats a pretty rubbish solution so has anyone else got any suggestions? I tried doing Window.Activate() after caling Window.Show() in my double click event but that doesnt help.<br/><br/>PS if anyone has a better way of achieving the whole double click event on a datatemplated listbox item then im all ears<br/><br/>Thanks<br/>Chris<hr class="sig">Windows XP MCP© 2009 Microsoft Corporation. All rights reserved.Mon, 06 Jul 2009 19:37:46 Ze62d4963-bf5b-4fa5-88d5-c96791ad54a3http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/e62d4963-bf5b-4fa5-88d5-c96791ad54a3#e62d4963-bf5b-4fa5-88d5-c96791ad54a3http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/e62d4963-bf5b-4fa5-88d5-c96791ad54a3#e62d4963-bf5b-4fa5-88d5-c96791ad54a3Chris128http://social.msdn.microsoft.com/Profile/en-US/?user=Chris128Listbox double click problemsOK so I have done the following to allow my listbox items (which use a datatemplate and are bound to an ObservableCollection in my code behind) to have a double click event:<br/><br/> <pre lang=x-xml>&lt;ListBox.ItemContainerStyle&gt; &lt;Style TargetType=&quot;ListBoxItem&quot;&gt; &lt;EventSetter Event=&quot;MouseDoubleClick&quot; Handler=&quot;User_DoubleClick&quot;/&gt; &lt;Setter Property=&quot;Template&quot; Value=&quot;{DynamicResource ListBoxItemHighlightCT}&quot;/&gt; &lt;/Style&gt; &lt;/ListBox.ItemContainerStyle&gt;</pre> So then my User_DoubleClick sub basically just does a few things and then needs to show a new window. The problem is that although it shows this new window, the window never has focus and so is hidden behind the main window that has the listbox on it. Im assuming the reason for this is because after the double click event is fired it runs the code in my User_DoubleClick sub and then returns focus to the main window.<br/><br/>The only 'solution' I have at the moment is to just use a timer in the Loaded event of the new window so that after say 500 ms it just uses Me.Activate() to bring itself into focus but needless to say thats a pretty rubbish solution so has anyone else got any suggestions? I tried doing Window.Activate() after caling Window.Show() in my double click event but that doesnt help.<br/><br/>PS if anyone has a better way of achieving the whole double click event on a datatemplated listbox item then im all ears<br/><br/>Thanks<br/>Chris<hr class="sig">Windows XP MCPThu, 02 Jul 2009 21:12:21 Z2009-07-02T21:12:21Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/e62d4963-bf5b-4fa5-88d5-c96791ad54a3#47d51609-ec29-444f-a7bb-1f197609adfdhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/e62d4963-bf5b-4fa5-88d5-c96791ad54a3#47d51609-ec29-444f-a7bb-1f197609adfdMark Salsberyhttp://social.msdn.microsoft.com/Profile/en-US/?user=Mark%20SalsberyListbox double click problemsDo you mark the event as handled in your event handler?  If not, does that help?<br/><br/><br/>Mark<br/><hr class="sig"> Mark Salsbery Microsoft MVP - Visual C++ Thu, 02 Jul 2009 22:04:53 Z2009-07-02T22:04:53Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/e62d4963-bf5b-4fa5-88d5-c96791ad54a3#b01dd15f-08d1-4431-819f-2c1d78a922bfhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/e62d4963-bf5b-4fa5-88d5-c96791ad54a3#b01dd15f-08d1-4431-819f-2c1d78a922bfChris128http://social.msdn.microsoft.com/Profile/en-US/?user=Chris128Listbox double click problemsNope because its not really an event handler, its just a sub that the event is routed to via the XAML I posted in my original post.<br/><br/>This is how I declare it:<br/> <pre lang=x-vbnet> Private Sub User_DoubleClick()</pre> Seen as it is used in an event setter in a style the way it is, how could I make it a 'proper' event handler?<hr class="sig">Windows XP MCPThu, 02 Jul 2009 22:13:07 Z2009-07-02T22:13:07Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/e62d4963-bf5b-4fa5-88d5-c96791ad54a3#7da6011f-82b7-43cc-a4e6-eca4145eba95http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/e62d4963-bf5b-4fa5-88d5-c96791ad54a3#7da6011f-82b7-43cc-a4e6-eca4145eba95Mark Salsberyhttp://social.msdn.microsoft.com/Profile/en-US/?user=Mark%20SalsberyListbox double click problems<blockquote>Nope because its not really an event handler, its just a sub that the event is routed to via the XAML I posted in my original post.<br/><br/>This is how I declare it:<br/> <div style="background-color:white;color:black"> <pre> <span style="color:blue">Private</span> <span style="color:blue">Sub</span> User_DoubleClick() </pre> </div> Seen as it is used in an event setter in a style the way it is, how could I make it a 'proper' event handler? <hr class=sig> Windows XP MCP</blockquote> <br/>Declare it like this perhaps (C#)<br/><br/> <pre lang="x-c#">void User_DoubleClick(Object sender, MouseButtonEventArgs e)</pre> <br/><strong><em>*edit*  In c# I can't successfully build unless I use the proper delegate for User_DoubleClick()</em></strong><br/>Thu, 02 Jul 2009 22:38:36 Z2009-07-02T22:44:37Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/e62d4963-bf5b-4fa5-88d5-c96791ad54a3#864dadc0-9233-41f6-965f-120b30f53f9bhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/e62d4963-bf5b-4fa5-88d5-c96791ad54a3#864dadc0-9233-41f6-965f-120b30f53f9bChris128http://social.msdn.microsoft.com/Profile/en-US/?user=Chris128Listbox double click problemsThanks Mark that worked perfectly :)<hr class="sig">Windows XP MCPMon, 06 Jul 2009 19:37:40 Z2009-07-06T19:37:40Z