gpt4 book ai didi

c# - 如何使用 Eto.Forms TreeGridView

转载 作者:行者123 更新时间:2023-11-30 23:04:35 27 4
gpt4 key购买 nike

我从事此工作已有一段时间了,但似乎无法弄清楚如何让 Eto.Forms TreeGridView 控件正确呈现。我现在正尝试添加一些 GridViewItem,但我只是在顶部得到一个灰色的小条:

enter image description here

这是我的代码:

        List<ITreeGridItem> treeGridItems = new List<ITreeGridItem>();
foreach (var contentType in contentTypes)
{
treeGridItems.Add(new TreeGridItem(contentType.Name));
}

Content = new DocumentPage(new TreeGridView
{
DataStore = new TreeGridItemCollection(treeGridItems)

}, new Padding(20));

我什至不确定从哪里开始,我现在只想得到一个带有文本的树来显示每个节点,但我什至做不到。

最佳答案

经过一些尝试和错误,我想出了如何使用 TreeView :

 var treeGridView = new TreeGridView
{
BackgroundColor = Colors.White
};

treeGridView.Columns.Add(new GridColumn
{
HeaderText = "Content Type",
DataCell = new TextBoxCell(0)
});

treeGridView.Columns.Add(new GridColumn
{
HeaderText = "Create",
DataCell = new CustomCell
{
CreateCell = r =>
{
TreeGridItem item = r.Item as TreeGridItem;

ContentTypeTag tag = (ContentTypeTag)item.Tag;
var contentType = _siteManager.CurrentSite.ContentTypes.First(x => x.Name.Equals(tag.ClassName));

void Click(object btnSender, EventArgs btnArgs)
{
//Your Event
}

var button = new LinkButton
{
Style = "primary-link-btn",
Text = $"Create {contentType.Name.ToSentenceCase()}",
Command = new Command(Click)
};

return button;
}
}
});

treeGridView.Columns.Add(new GridColumn
{
HeaderText = "Show All",
DataCell = new CustomCell
{
CreateCell = r =>
{
TreeGridItem item = r.Item as TreeGridItem;

ContentTypeTag tag = (ContentTypeTag)item.Tag;
var contentType = _siteManager.CurrentSite.ContentTypes.First(x => x.Name.Equals(tag.ClassName));

void Click(object btnSender, EventArgs btnArgs)
{
//Your Event
}

var button = new LinkButton
{
Style = "primary-link-btn",
Text = $"Show All {contentType.Name.ToSentenceCase()}",
Command = new Command(Click)
};

return button;
}
}
});

var treeGridItemCollection = new TreeGridItemCollection();
foreach (var contentType in _siteManager.CurrentSite.ContentTypes)
{
var item = new TreeGridItem
{
Values = new string[] { contentType.Name.ToSentenceCase(), "Create", "Show All" },
Tag = new ContentTypeTag
{
ClassName = contentType.Name
}
};

treeGridItemCollection.Add(item);
}

treeGridView.DataStore = treeGridItemCollection;

您先创建标题列,然后创建一个 TreeGridItemCollection 并将数据存储设置为该集合。该行的每一列的值在字符串数组中设置为 TreeGridItem 的 Values 属性。

关于c# - 如何使用 Eto.Forms TreeGridView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49348488/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com