c# - 如何避免得到负值?

标签 c# silverlight

我需要能够避免获得负值。调整窗口浏览器的大小但不达到负值时,我需要收缩数据网格,以免出错。那可能吗?先感谢您。

这是我的代码:

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/

相关文章:

silverlight - ItemTemplate 中 DataContext 的访问属性

c# - 有没有办法对 for 循环进行编码,使其不会在序列中递增?

silverlight - Silverlight 的依赖注入(inject)?

.net - IDataErrorInfo.Error 应该检查每个属性吗?

c# - 带有 MySql 的 Log4net 不记录

.net - 将 clientaccesspolicy.xml 放在 Silverlight 项目中的什么位置

silverlight - Windows phone 7 滚动查看器问题

c# - 为什么我们使用时间跨度从另一个日期减去一个日期时得到负值

c# - ASP.Net 注册表中的 MS Captcha 超时持续时间

java - strip 池中可能出现饥饿且死锁为真 - Apache Ignite