Windowsストアアプリケーションでディスプレイサイズの合わせて表示を調整したい場合があります。
その場合はディスプレイサイズの変更はSizeChangedイベントで取得します。
あわせてDPIを取得するコードも紹介します。
public MainPage()
{
this.InitializeComponent();
this.SizeChanged += MainPage_SizeChanged;
DisplayProperties.LogicalDpiChanged += DisplayProperties_LogicalDpiChanged;
}
void DisplayProperties_LogicalDpiChanged(object sender)
{
this.dpiText.Text = DisplayProperties.LogicalDpi.ToString();
}
void MainPage_SizeChanged(object sender, SizeChangedEventArgs e)
{
this.widthText.Text = e.NewSize.Width.ToString();
this.heightText.Text = e.NewSize.Height.ToString();
this.dpiText.Text = DisplayProperties.LogicalDpi.ToString();
}
実行可能なサンプルコードは以下、シミュレーターでいろいろサイズを変えて試してみてください。
Please give us your valuable comment