Version

Handle Window State Changing Events

There are two events associated when the dialog window’s state changes. These events have the suffix “ing” or “ed” appended to them, reflecting the order in which they occur. The window state changing events allow you to perform some custom business logic before or after the window’s state is changed.

WindowStateChanging - The moment right before the dialog window control’s state changes, the WindowStateChanging event fires. You can cancel this event if certain conditions are not met.

WindowStateChanged -This event fires after the dialog window control’s state is changed.

The following code demonstrates how to handle the WindowStateChanging and WindowStateChanged events.

In XAML:

<Grid x:Name="LayoutRoot" Background="White">
   <ig:XamDialogWindow Content="Dialog Window"
      x:Name="DialogWindow"
      Width="200" Height="200"
      WindowStateChanged="DialogWindow_WindowStateChanged"
      WindowStateChanging="DialogWindow_WindowStateChanging"/>
</Grid>

In Visual Basic:

Imports Infragistics.Controls.Interactions
…
AddHandler DialogWindow.WindowStateChanging, AddressOf DialogWindow_WindowStateChanging
AddHandler DialogWindow.WindowStateChanged, AddressOf DialogWindow_WindowStateChanged
…
Private Sub DialogWindow_WindowStateChanging(ByVal sender As System.Object, ByVal e As WindowStateChangingEventArgs)
  'If the new window state is minimized,cancel the event
   If (e.NewWindowState.Equals(WindowState.Minimized)) Then
      e.Cancel = True
      Return
   End If
   System.Diagnostics.Debug.WriteLine("Window State Changing from "
                                       + e.CurrentWindowState.ToString() +
                                       " to " + e.NewWindowState.ToString())
End Sub
Private Sub DialogWindow_WindowStateChanged(ByVal sender As System.Object, ByVal e
As WindowStateChangedEventArgs)
   System.Diagnostics.Debug.WriteLine("Window State Changed Successfully")
End Sub

In C#:

using Infragistics.Controls.Interactions;
…
DialogWindow.WindowStateChanging += new EventHandler<WindowStateChangingEventArgs>(DialogWindow_WindowStateChanging);
DialogWindow.WindowStateChanged += new EventHandler<WindowStateChangedEventArgs>(DialogWindow_WindowStateChanged);
…
void DialogWindow_WindowStateChanged(object sender, WindowStateChangedEventArgs e)
{
   System.Diagnostics.Debug.WriteLine("Dialog Window State Changed Successfully");
}
void DialogWindow_WindowStateChanging(object sender, WindowStateChangingEventArgs e)
{
   //If the new window state is minimized,cancel the event
   if(e.NewWindowState.Equals(WindowState.Minimized))
   {
      e.Cancel = true;
      return;
   }
   System.Diagnostics.Debug.WriteLine("Window State Changing from "+e.CurrentWindowState+" to "+e.NewWindowState);
}