當我用行或列創建網格時,如果我沒有指定寬度/高度,列/行將它的高度/寬度調整為它的內容,如下所示:
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Button Content="TestBtn"
Height="50"
Width="100"/>
</Grid>
行將其高度設定為 50。
問題:在代碼中自定義設定寬度/高度后,如何將行/列回傳到默認行為?像這樣:
public void SetRowHeight(double height, bool setDefault)
{
if (setDefault)
{
Grid0Row1.DefaultHeightBehaivor = true;
}
else
{
Grid0Row1.Height = new GridLength(Height);
}
}
uj5u.com熱心網友回復:
為此,您需要使用new GridLength()空引數,代碼將如下所示:
public void SetRowHeight(double height, bool setDefault)
{
if (setDefault)
{
Grid0Row1.Height = new GridLength();
}
else
{
Grid0Row1.Height = new GridLength(height);
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/426001.html
