How to say XAML <Button Height=“Auto”/> in code behind?

泪湿孤枕 提交于 2019-12-03 04:58:01

问题


How can you set Height="*" and Height="Auto" in code behind?


回答1:


For setting Height = "Auto" on most controls, you want to assign the value with double.NaN.

Example:

element.Height = double.NaN;

Setting Width/Height = "*" ( is a slightly different matter, since it only applies to a select few elements (ColumnDefinition and RowDefinition for example). The type of the Width/Height value is GridLength, rather than double.

Example (more are given on this MSDN page:

column1.Width = new GridLength(1, GridUnitType.Auto); // Auto
column2.Width = new GridLength(1, GridUnitType.Star); // *


来源:https://stackoverflow.com/questions/1497921/how-to-say-xaml-button-height-auto-in-code-behind

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!