WPF Window最小化ボタン処理のフック

[WPF Tips]

WPF アプリケーション作成で得たTipsをメモ

1.状況

モーダルダイアログウィンドウを作成し、時間のかかる処理の状況を表示させるのだが、最小化してもダイアログだけ最小化されてしまう。呼び出し側のウィンドウも併せて最小化させたい。

2.対応

モーダルウィンドウ表示時に、Ownerプロパティにメインウィンドウをセット、ウィンドウのステート変更をフックし、ダイアログが最小化された場合、Ownerも最小化する。

3.参考

4.サンプル

  1. public partial class ProgressDialog : Window
  2. {
  3. public ProgressDialog()
  4. {
  5. InitializeComponent();
  6. this.StateChanged += new EventHandler(Window_StateChanged);
  7. }
  8.  
  9. void Window_StateChanged(object sender, EventArgs e)
  10. {
  11. if (this.WindowState == WindowState.Minimized)
  12. {
  13. if (this.Owner != null)
  14. {
  15. this.Owner.WindowState = WindowState.Minimized;
  16. }
  17. }
  18. }
  19. }

Follow me!

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です