WPF 寬度跟父控件(或者另一個控件)走

<UserControl
    Width="{Binding RelativeSource=
            {RelativeSource FindAncestor,
            AncestorType={x:Type ListView}},
            Path=ActualWidth}"
    Height="{Binding RelativeSource=
            {RelativeSource FindAncestor,
              AncestorType={x:Type ListView}},
              Path=ActualHeight}">
<!-- Content -->
  </UserControl>

  來自

 

 <hc:ScrollViewer x:Name="scrList"  >
            <WrapPanel Orientation="Horizontal" Width="{Binding ElementName=scrList, Path=Width, Mode=OneWay}" HorizontalAlignment="Center">

注意綁定  Mode = OneWay(a => b, b ≠> a)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章