将自动将子项添加到单独的行中。所以我创建了自己的网格,添加方法来添加新行并将其处理为OnVisualChildrenChanged。但是,只要我在其中添加新的UIElement,RowDefinitions.IsReadOnly属性为true,我就不能这样做。
public class GridWithAutoRows : Grid
{
public void AddRow()
{
this.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Star) });
}
protected override void OnVisualChildrenChanged(DependencyObject visualAdded, DependencyObject visualRemoved)
{
this.AddRow();
Grid.SetRow(visualAdded as UIElement, this.RowDefinitions.Count - 1);
base.OnVisualChildrenChanged(visualAdded, visualRemoved);
}
}
感谢您的任何想法。