tags:

views:

49

answers:

3

I have an items control on my window and when its double clicked I want to open a second window. My problem is that if the items control is wrapped in a scroll viewer the new window comes up behind the main window instead of in front of it. If comment out the scroll viewer in this code the window opens in front as intended.

Whats going on here?


Window XAML:

<Window x:Class="EktronDataUI.TestWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="TestWindow" Height="300" Width="300">
    <Grid>
        <ScrollViewer>
            <ItemsControl ItemsSource="{Binding Source={StaticResource odpMockSmartForms}}" MouseDoubleClick="ItemsControl_MouseDoubleClick" >
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <TextBlock Text="Double Click Me" />
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ItemsControl>
        </ScrollViewer>
    </Grid>
</Window>

Code Behind:

    private void ItemsControl_MouseDoubleClick(object sender, MouseButtonEventArgs e)
    {
        TestWindow window = new TestWindow();
        window.Show();
    }
A: 

Not sure... but does the issue get fixed if you remove your scrollviewer, and instead use:

<ItemsControl ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto"/>
Scott
Yes and no. The window shows up in front like its supposed to, but the contents don't scroll
Mr Bell
Using this approach, did you try explicitly constraining the height/width of the grid?
Ragepotato
A: 

I pulled in your code and got it to pull to the front if I set the TopMost equal to true.

private void ItemsControl_MouseDoubleClick(object sender, MouseButtonEventArgs e)
    {
        TestWindow window = new TestWindow();

        window.Show();
        window.Topmost = true;

    }

Is this what you're looking for?

JSprang
Sorry about this, I was in the Silverlight mindset :(
JSprang
Edited answer for WPF.
JSprang
+1  A: 

Have you tried telling the MouseButtonEventArgs that you handled it? The ScrollViewer is most likely trying to focus or do something else when you double click inside it, causing the window to become active again after the other window is opened.

private void ItemsControl_MouseDoubleClick(object sender, MouseButtonEventArgs e)
    {
        e.handled = true;
        TestWindow window = new TestWindow();
        window.Show();
    }
rossisdead