0

Parent window freezes when I open a window on click of a button. It works properly again if I minimize and maximize parent window again.

System configuration

  • Windows 7, 64 bit OS.
  • .Net framework 3.5 SP1
  • Visual studio express 2008

Following is the simple application where I can reproduce this issue.

Window1.xaml

<Window x:Class="WpfApplication1.Window1"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  Title="Window1" Height="300" Width="300">
  <StackPanel>
    <TextBox Width="200"/>
    <Button Content="click" Click="Button_Click"/>
  </StackPanel>
</Window>

Window1.xaml.cs

namespace WpfApplication1 {
/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>
public partial class Window1 : Window {
    public Window1() {
        InitializeComponent();
    }

    private void Button_Click(object sender, RoutedEventArgs e) {
        (new Window2()).ShowDialog();
    }
}
}

Window2.xaml

<Window x:Class="WpfApplication1.Window2"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window2" Height="300" Width="300" WindowStyle="ToolWindow">
<Grid>

</Grid>
</Window>

It works fine if I remove WindowStyle="ToolWindow" !!!!!!

App.xaml

<Application x:Class="WpfApplication1.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="Window1.xaml">
<Application.Resources>

</Application.Resources>
</Application>
Anatoliy Nikolaev
  • 22,370
  • 15
  • 69
  • 68
naveen
  • 21
  • 1
  • 5

4 Answers4

1

The call to ShowDialog() is blocking your GUI thread.

See this question for alternative approaches which don't block the main thread.

Community
  • 1
  • 1
Ian Gregory
  • 5,770
  • 1
  • 29
  • 42
1

Use Show instead of ShowDialog which opens a window in Modal mode

Emond
  • 50,210
  • 11
  • 84
  • 115
1

If you use ShowDialog() try set Window1 as Owner for Window2:

        Window2 w = new Window2 { Owner = this };
        w.ShowDialog();
chameleon
  • 984
  • 10
  • 15
1

Show instead of show dialog will work, but maybe you intention was something more like a child window see http://wpftoolkit.codeplex.com/wikipage?title=ChildWindow&referringTitle=Home for details.

DermFrench
  • 3,968
  • 13
  • 43
  • 70