我需要能够避免获得负值。调整窗口浏览器的大小但不达到负值时,我需要收缩数据网格,以免出错。那可能吗?先感谢您。
这是我的代码:
public SilverlightResizeTest()
{
InitializeComponent();
// Set the height for the DataGrid when the browser window changes size
App.Current.Host.Content.Resized += new System.EventHandler(Content_Resized);
// Set the initial height for the DataGrid
double x = App.Current.Host.Content.ActualHeight;
if (x != 0)
{
DataGrid.Height = (x - 485.0);
}
}
void Content_Resized(object sender, System.EventArgs e)
{
// Set the height for the DataGrid when the browser window changes size
double x = App.Current.Host.Content.ActualHeight;
if (x != 0)
{
DataGrid.Height = (x - 485.0);
}
}
最佳答案
DataGrid.Height = Math.Max(0.0, x - 485.0);
关于c# - 如何避免得到负值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5953217/