WPF: Setting the Width (and Height) as a Percentage Value

前端 未结 7 589
悲&欢浪女
悲&欢浪女 2020-11-27 10:59

Say I want a TextBlock to have its Width equal to it\'s Parent container\'s Width (ie, stretch from side to side) or a percentage of

相关标签:
7条回答
  • 2020-11-27 11:44

    The way to stretch it to the same size as the parent container is to use the attribute:

     <Textbox HorizontalAlignment="Stretch" ...
    

    That will make the Textbox element stretch horizontally and fill all the parent space horizontally (actually it depends on the parent panel you're using but should work for most cases).

    Percentages can only be used with grid cell values so another option is to create a grid and put your textbox in one of the cells with the appropriate percentage.

    0 讨论(0)
提交回复
热议问题