2012-03-27 32 views
0

我正在實施WPF DataGrid中的調整大小功能,它支持通過列/行標題重新調整大小,但我想要的是允許在網格線上重新調整大小。添加DataGrid調整能力

因此,用戶可以從DataGrid中的任何位置重新調整行/列的大小。我已經能夠實現這些功能,並且對於列來說工作正常,但是在行被搞砸的情況下。

您可以通過標題重新調整行大小,也可以通過該行的任何單元重新調整大小,但是如果一起使用它們,則會發生問題,即一旦重新調整單元格大小,重新調整大小行標題將停止工作(顯示奇怪的行爲)。這裏是如何的樣子(注意破網格線...) -

enter image description here

我創建了一個樣本重現此問題 -

WPF Toolkit DataGrid Sample - Adding GridLines Resizing

要重現該問題

  1. 通過網格線(任意單元格)重新調整行大小然後

  2. 通過行標題重新設置同一行。

將不勝感激任何形式的幫助。

感謝

回答

0

我通過設置CellPresenter,而不是行的高度解決了這個問題。這裏是主代碼塊 -

double newHeight = cellsPresenter.ActualHeight + e.VerticalChange;  
DataGridRowHeader rowHeader = GetFirstVisualChild<DataGridRowHeader>(row);  
if (rowHeader != null)  
{ 
    // clamp the CellsPresenter size to the MaxHeight of Row, 
    // because row wouldn't grow any larger 
    double maxHeight = row.MaxHeight; 
    if (newHeight > maxHeight) 
    { 
     newHeight = maxHeight; 
    } 
} 

cellsPresenter.Height = newHeight; 

// Updating row's height doesn't work correctly; shows weird behavior  
// row.Height = newHeight >= 0 ? newHeight : 0; 

我進行了詳細的博客上講述這個在這裏 -

WPF DataGrid Customization: Resizing Row/Column through DataGridCell gridlines