我想知道我使用的代碼有什麼問題。我想通過下面提供的代碼來限制基於瀏覽器窗口的數據網格的高度調整大小。也許,有一個更好的方法來做到這一點。任何建議是高度讚賞。如何根據窗口大小限制調整大小的Datagrid?
當我調整窗口的大小比我收到錯誤太多。
* System.ArgumentException由用戶代碼未處理 消息=值不在預期範圍內。 堆棧跟蹤: 在MS.Internal.XcpImports.CheckHResult(UInt32的小時) 在MS.Internal.XcpImports.SetValue(IManagedPeerBase OBJ,的DependencyProperty屬性,雙人d) 在System.Windows.DependencyObject.SetValue(的DependencyProperty屬性,雙人d ) at System.Windows.FrameworkElement.set_Height(Double value) at SilverlightResizeTest.Content_Resized(Object sender,EventArgs e) at System.Windows.Interop.Content.FireResized(Object sender,EventArgs args) at System.Windows。 Interop.SilverlightHost.FireResized(Object sender,EventArgs args) at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj,IntPtr unmanagedObjArgs,Int32 argsTypeIndex,Int32 actualArgsTypeIndex, String eve ntName) 的InnerException:*
代碼:
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);
}
}
我需要能夠避免從我包括的代碼的負值。你的方式適合完成不同的任務。再次感謝你。 – vladc77 2011-05-10 16:17:49
在這種情況下,只需檢查x> = 485,然後再減去。基於這個答案,你可以減去485或將x設置爲0。 – Danexxtone 2011-06-02 15:48:11