[英]WPF DataGrid on Custom Panel
I create a custom panel : 我创建一个自定义面板:
public class TowColumnWrapPanel : Panel
{
//Here have Dependency Properties: RowSpacing, ColumnSpacing, ColumnsCount
protected override Size ArrangeOverride(Size arrangeSize)
{
List<int> shownChildIndexes = new List<int>();
for (int i = 0; i < VisualChildrenCount; i++)
{
if (Children[i].Visibility == System.Windows.Visibility.Visible)
shownChildIndexes.Add(i);
}
if (shownChildIndexes.Count == 1)
{
//on my example I use the code below:
var child = Children[shownChildIndexes[0]];
var r = new Rect(0, 0, arrangeSize.Width, arrangeSize.Height);
if (child as FrameworkElement != null)
(child as FrameworkElement).MaxWidth = arrangeSize.Width;
child.Arrange(r);
}
else
{
//Some functionality here for lot childs!!
}
return base.ArrangeOverride(arrangeSize);
}
}
Meaning of the above class is that all children will have the same size, and will be stretched on one column / two column (optional to the user) 上一类的意思是所有子级都将具有相同的大小,并且将在一列/两列上拉伸(用户可选)
Everything works well! 一切正常!
Except of course for the DataGrid !!!! 当然除了DataGrid !!!!
When I have a DataGrid on my custom panel. 当我的自定义面板上有一个DataGrid时。 It looks like this: 看起来像这样:
Before resize (it's fine): 调整大小之前(可以):
After Resize: (Somehow adds infinite column) 调整大小后:(以某种方式添加无限列)
I don't understand why is happened, a little help would help! 我不明白为什么会发生,只有一点帮助会有所帮助!
I missed this function: MeasureOverride
- can be seen at the link below: 我错过了此功能: MeasureOverride
可以在下面的链接中看到:
http://www.codeproject.com/Articles/238307/A-Two-Column-Grid-for-WPF http://www.codeproject.com/Articles/238307/A-Two-Column-Grid-for-WPF
This is what caused the problems in the DG. 这就是导致 DG中出现问题的原因。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.