3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

WPFでウィンドウサイズに合わせてコントロールをリサイズするには

Last updated at Posted at 2025-03-22

Q.「ViewBoxがあるじゃん!」

A. あいつはGridの指定を無視して配置してきやがるので駄目です

LayoutTransform最強!

以下のように対象のGridやCanvasにLayoutTransformを指定して、リサイズイベントで比率を計算してやると幸せになります

<Grid>
    <Grid.LayoutTransform>
        <ScaleTransform x:Name="Scale"/>
    </Grid.LayoutTransform>
</Grid>
private void OnSizeChanged(object sender, SizeChangedEventArgs e)
{
    // defaultWidthとdefaultHeightは各自で
    Scale.ScaleX = ActualWidth / defaultWidth;
    Scale.ScaleY = ActualHeight / defaultHeight;
}
3
3
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
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?