2011-05-10 4 views
1

음수 값을 피할 수 있어야합니다. 창 브라우저의 크기를 조정할 때 오류가 발생하지 않도록 음수 값에 도달하지 않을 때 축소하려면 DataGrid가 필요합니다. 그게 가능하니? 미리 감사드립니다.음수 값을 피하는 방법은 무엇입니까?

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); 
     } 
    } 

답변

3
DataGrid.Height = Math.Max(0.0, x - 485.0); 
+0

그것은 잘 작동합니다. 도와 주셔서 감사합니다! 나는 그것을 아주 좋아한다. – vladc77

3

어느 쪽이

DataGrid.Height = Math.Max(0, x - 485.0); 

또는이

DataGrid.Height = (x - 485.0); 
if(DataGrid.Height < 0) DataGrid.Height = 0; 

또는 ...

,691 : 여기

내 코드입니다

정말, 할 수있는 방법이 많습니다. 사용 :

1

새로운 높이가 0이 될 경우가 Content_Resized 방법

DataGrid.Height = x > (485.0) ? (x - 485.0) : DataGrid.Height; 

이 방법을 ONN이 시도 할 수 있습니다, 그것은 대신 또한 최소 높이 사 데이터 그리드를 정의 할 수 있습니다, 이전의 높이를 유지 이 줄 대신 :

DataGrid.Height = x > (485.0 + minHeight) ? (x - 485.0) : DataGrid.Height; 
1

왜 확인하지 않으시겠습니까? :

DataGrid.Height = Math.Max(0 , x - 485.0); 
1
DataGrid.Height = Math.Max((x - 485.0), 0.0); 
+0

잘 작동합니다. 실제로 그것을 달성하기위한 제안 된 모든 방법이 나를 위해 작동합니다. 도와 주셔서 감사합니다! 나는 그것을 아주 좋아한다. – vladc77

관련 문제