I have a MouseDoubleClick event handler defined in a ListView.ItemContainerStyle definition as such:
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<EventSetter Event="MouseDoubleClick" Handler="MyClass_MouseDoubleClick" />
</Style>
</ListView.ItemContainerStyle>
The event handler is defined as:
private void MyClass_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
ListViewItem listViewItem = (ListViewItem)sender;
MyClass senderItem = (MyClass)(listViewItem.Content);
EditFile editFileWindow = new EditFile(senderItem);
editFileWindow.Show();
}
This works as expected with the exception that the new window displays behind my main application window when it pops up. How can I set focus to the new window after it’s loaded?
I tried adding this.Focus() at the end of my window’s class constructor but it didn’t change anything.
Try this: