HorizontalAlignment=Stretch, MaxWidth, and Left aligned at the same time?

前端 未结 8 2405
隐瞒了意图╮
隐瞒了意图╮ 2020-12-04 14:47

This seems like it should be easy but I\'m stumped. In WPF, I\'d like a TextBox that stretches to the width of it\'s parent, but only to a maximum width. The problem is that

8条回答
  •  暖寄归人
    2020-12-04 15:42

    You can use this for the Width of your DataTemplate:

    Width="{Binding ActualWidth,RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ScrollContentPresenter}}}"
    

    Make sure your DataTemplate root has Margin="0" (you can use some panel as the root and set the Margin to the children of that root)

提交回复
热议问题