具有自动列和行定义的Xamarin自定义网格视图

时间:2019-02-05 10:52:59

标签: c# xamarin xamarin.forms xamarin.ios

我正在尝试扩展Grid并根据XAML中添加的子代数量实现自动的行和列处理以及索引。因此,我只需要定义行和列,然后视图就基本上按照xaml中列出的顺序填充了子级。

我将Grid扩展如下

namespace Foo.Controls
{
    public class KeyValueGrid : Grid
    {
        public KeyValueGrid() : base()
        {
            Console.WriteLine($"KeyValueGrid() We have {Children.Count} childs.");
        }

        protected override void OnInitialized()
        {
            // rebuild row and col defs based on this.Children
        }
    }
} 

但是,方法OnInitialized()已被删除/过时。有什么方法可以说明View是完全由XAML构造的吗?

我要实现的表/网格看起来像这样:

|----------------------------------------------|
|         Section Caption                      |
|----------------------------------------------|
|                 Key | Value                  |
|----------------------------------------------|
|                 Key | Value                  |
|----------------------------------------------|
|          ...        |                        |
|----------------------------------------------|

0 个答案:

没有答案
相关问题