您不打算設置行本身的高度,因爲它通過標題等進行了調整。有一個屬性,DataGrid.RowHeight
,它可以讓你做到這一點。
如果您需要設置高度選擇性,你可以創建一個風格和DataGridCellsPresenter
的高度綁定到一些財產上的物品:
<DataGrid.Resources>
<Style TargetType="DataGridCellsPresenter">
<Setter Property="Height" Value="{Binding RowHeight}" />
</Style>
</DataGrid.Resources>
或者你可以從可視化樹主持人(我不要不提倡這種做法),並指定一個高度有:
// In LoadingRow the presenter will not be there yet.
e.Row.Loaded += (s, _) =>
{
var cellsPresenter = e.Row.FindChildOfType<DataGridCellsPresenter>();
cellsPresenter.Height = 120;
};
哪裏FindChildOfType
是可以這樣來定義的擴展方法:
public static T FindChildOfType<T>(this DependencyObject dpo) where T : DependencyObject
{
int cCount = VisualTreeHelper.GetChildrenCount(dpo);
for (int i = 0; i < cCount; i++)
{
var child = VisualTreeHelper.GetChild(dpo, i);
if (child.GetType() == typeof(T))
{
return child as T;
}
else
{
var subChild = child.FindChildOfType<T>();
if (subChild != null) return subChild;
}
}
return null;
}
謝謝閣下。解決問題:) – MegaMilivoje 2012-02-04 18:16:47