LoginSignup
4
4

More than 5 years have passed since last update.

コントロールの高さや幅にWindowの高さや幅をバインドする方法

Last updated at Posted at 2016-11-23

Frameなんかを使っていてそのFrameのサイズが動的に変わる場合、
Frameをはめ込んでいる親ItemのサイズもFrameにつられて変わってしまう。

そんな時とりあえず親ItemのサイズはWindowのサイズに合わせたいってことがあると思いますが
こんな感じでWindowのサイズをバインドできます。

コードは幅をバインドさせてるけどHeightに変えれば高さをバインドできます。
また、AncestorTypeのx:TypeにGridを指定すればWindowじゃなくGridをバインドさせることができます。

<StackPanel Width="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=Width}">
    <Frame NavigationUIVisibility="Hidden" Name="XXXX" Content="{Binding XXXXPage}" />
</StackPanel>
4
4
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
4
4