0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Prism.WPFのIDialogService.ShowDialogで画面のセンターに表示させる

Last updated at Posted at 2021-01-10

環境

Visual Studio 2019
Prism 8.0.0.1909
.NET5

問題

アプリを起動するときにログインフォームを開くということがあると思います。
このログインフォームをIDialogService.ShowDialogを利用して表示させようとしましたが、オーナーウィンドウから呼び出すと、.Net Framework 4.8 の時はオーナーウィンドウが先に表示されて、それからダイアログが表示されていました。
ところが、.NET5にしたところ、オーナーウィンドウが表示されず、先にダイアログが表示されるようになっていました。
すると、ダイアログが適当な位置に表示されてしまい、画面の中央に表示するということができなくなってしまいました。

dialogService.ShowDialog(PageKeys.Login, new DialogParameters { { "Login", inputValue } }, result => dialogResult = result);

スクリーンショット 2021-01-11 002128.png
よく見ると、オーナーウィンドウはあるようなのですが、透明でまだ表示されていなくて、ダイアログはそれに合わせて中央に表示というようにできないみたいでした。

解決

いろいろと調べていたところ、PrismLibraryに解決方法が書かれていました
Style the DialogWindow
You can control the properties of the DialogWindow by using a style via an attatched property on the Dialog UserControl

<prism:Dialog.WindowStyle>
    <Style TargetType="Window">
        <Setter Property="prism:Dialog.WindowStartupLocation" Value="CenterScreen" />
        <Setter Property="ResizeMode" Value="NoResize"/>
        <Setter Property="ShowInTaskbar" Value="False"/>
        <Setter Property="SizeToContent" Value="WidthAndHeight"/>
    </Style>
</prism:Dialog.WindowStyle>

いろいろ知らないことがあります(~_~;)

0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?