WPF Auto height in code

后端 未结 2 1323
孤街浪徒
孤街浪徒 2021-01-31 23:58

How could I set the value of the Height property of a WPF control in C# code to \"Auto\"?


    

        
相关标签:
2条回答
  • 2021-02-01 00:36

    Perhaps this link will help you.

    At times, you may want to programmatically set the Height or Width of a WPF element to Auto in code. To do this, just use the Double.NaN (Not a Number) value.

    For example, in C#:

    this.txtName.Width = Double.NaN;

    0 讨论(0)
  • 2021-02-01 00:44

    You can use

    RowDefinition rd = new RowDefinition();  
    rd.Height = GridLength.Auto;  
    ContentGrid.RowDefinitions.Add(rd);
    
    0 讨论(0)
提交回复
热议问题