- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我想获取对象的平面列表并使用自定义组将它们呈现在 TreeView 中。
public enum DocumentType { Current, Inactive, Transition, Checkpack, TechLog, Delivery }
public enum Status { Approved, Rejected, Pending }
public class Document
{
public string Name { get; set; }
public DateTime Created { get; set; }
public string CreatedBy { get; set; }
public DateTime Modified { get; set; }
public string ModifiedBy { get; set; }
public DocumentType Type { get; set; }
public Status Status { get; set; }
}
例如...用户可能希望看到此列表,其中顶级组是“状态”,第二级是“姓名”。这一切都需要从 UI 进行配置,我正在努力寻找实现它的最佳方法。
我已经简要地查看了 CollectionViewSource 对象,但找不到让它动态构建 TreeView 的好方法。
我的直觉是我需要在 XAML 中做一些巧妙的模板制作——这是我所能做的...
<Window.Resources>
<DataTemplate x:Key="DocumentTemplate">
<DockPanel>
<TextBlock Text="{Binding Name}" />
</DockPanel>
</DataTemplate>
<HierarchicalDataTemplate x:Key="GroupTemplate"
ItemsSource="{Binding Path=Items}"
ItemTemplate="{StaticResource DocumentTemplate}">
<TextBlock Text="{Binding Path=Name}" />
</HierarchicalDataTemplate>
</Window.Resources>
<Grid>
<TreeView ItemsSource="{Binding Documents.View.Groups}"
ItemTemplate="{StaticResource GroupTemplate}"/>
</Grid>
public CollectionViewSource Documents
{
get
{
var docs = new CollectionViewSource();
docs.Source = DocumentFactory.Documents;
docs.GroupDescriptions.Add(new PropertyGroupDescription("CreatedBy"));
return docs;
}
}
当然这只会显示顶级组(“CreatedBy”)。
阅读下面的问题后,我想出了一个更好的问题...
我的问题:是否可以为显示应用于 CollectionViewSource 的自定义组的 TreeView 使用通用的 HierarchicalDataTemplate。
最佳答案
老实说,这应该被标记为 WPF 中的错误。我也尝试过,发现 Documents.View.Groups
在 View
属性为 null 时抛出绑定(bind)错误。
还有
<TextBlock Text="{Binding Path=Name}" />
在 GroupTemplate
中正确,但在 DocumentTemplate
中不正确。请注意,Groups
属于特殊类型 GroupItem
,其中 Name
是一种此类属性,它保存发生分组的值。
另一方面,在 DocumentTemplate
中,我们应该引用我们需要在叶节点项上显示的属性,例如在我的示例中,我使用了 Employee.FirstName
(我按 Gender
分组)。
<DataTemplate x:Key="DocumentTemplate">
<DockPanel>
<TextBlock Text="{Binding FirstName}" />
</DockPanel>
</DataTemplate>
现在为了使绑定(bind)生效,我必须引入一个转换器,它只返回 Groups
。
public class GroupsConverter : IValueConverter
{
public object Convert(object value, ...)
{
return ((CollectionViewSource)value).View.Groups;
}
....
}
并且 TreeView 绑定(bind)被这样改变了......
<TreeView x:Name="treeView"
ItemsSource="{Binding Path=Documents,
Converter={StaticResource GroupsConverter}}"
ItemTemplate="{StaticResource GroupTemplate}" />
然后这对我有用。
这对你有帮助吗?
关于c# - 在 TreeView 中动态分组/嵌套平面数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7512041/
我在一页上有两个 Kendo UI TreeViews。例如: var data1 = new kendo.data.HierarchicalDataSource({ data: [
使用 Vuetify 的 TreeView 组件时,我试图能够选择父级 没有 让它也选择所有的后代( child )。我尝试了可选、可激活等的各种组合……但似乎找不到合适的组合。 任何人都有实现这一预
在我的应用程序中,左侧有一个 TreeView,我根据 TreeView 中的选择更新右侧的 Pane 。一个非常直接的场景。当选择为空时,我会在 Pane 中显示一条类似“请进行选择”的消息,即我还
我有一个我自己无法解决的问题。请帮忙。 我有(有条件地): /** @mainpage A @subpage B */ /** @page B @subpage C */ /** @page C */
我制作了一个高度为 40 px 的自定义树单元。 这里的问题披露三角形没有垂直居中对齐。 这里是树单元的代码: public static class TestObjectCell extends A
我正在学习如何使用 kotlin 并已开始使用tornadoFX。我正在阅读该指南以尝试学习它,但是我无法弄清楚“具有不同类型的 TreeView”中的含义。似乎是说我应该使用星形投影,据我所知,当您
如何在 JavaFX 2 TreeView 中过滤节点? 我有一个 TextField,我想根据 TextField 的内容过滤所有节点(例如节点标签)。 谢谢。 最佳答案 这是我编写的可重用的可过滤
我正在通过查询 sharepoint 用户配置文件构建一个 asp.net TreeView 。要选择的帐户名和根节点帐户名正在从查询字符串中读取。 我还需要为树配置可配置的扩展深度。 如果节点属于第
我使用的是 JavaFX 8,目前正在进行一些 GUI 开发。我的 TreeView 有点问题,我需要你的帮助。 您知道在 TreeView 中是否可以只选择标签而不是 TreeCell 的整个宽度吗
我有很多(分层的)数据显示在 TreeView 中(可能是大约 20K 项或更多,包括子项)。我的数据的特殊问题是 TreeView 中显示的每个对象都可以存在于许多 TreeView 项目中。我的意
有没有什么简单的方法可以让 Gtk.Treeview 在编辑时更新它的列? 我基于 Gtk.ListStore 模型构建了 Treeview。我这样初始化单元格: Gtk.CellRendererTe
我开始使用 javafx。我有一个问题。我有一个树 View ,其中节点通过外部命令改变了他的位置,但它只是看不到树。我必须最小化父级并重新展开才能看到效果。 Altem 对该树 View 的任何建议
如何在 Kendo Treeview 中取消选择节点? 我尝试从节点中删除类“k-state-selected”。它工作正常,但有没有直接的方法可以做到这一点。 最佳答案 现在有一种更好的方法可以取消
我有以下情况,我有一个带有许多嵌套子节点的父节点。只有父节点应该有一个复选框,我发现的唯一例子是只有子节点有一个复选框。这可以使用 Kendo 模板吗? http://dojo.telerik.com
我正在尝试向 TreeView 数据项添加一些内联图标,但是 k-template 指令似乎没有呈现任何内容。 我基于在线文档在 http://demos.telerik.com/k
我有一个带有复选框和父节点和子节点的 Kendo Treeview 。 我需要将选中节点的完整层次结构复制到另一个 Treeview 中。 ex - 根节点、父节点和选中的子节点。 下面是我的代码,但
我需要在较大的滚动 Pane 中使用 JavaFX 2.2 TreeView 控件,该滚动 Pane 具有多个不属于 Treeview 的其他元素。问题是 TreeView 有它自己的内置滚动 Pan
当我通过单击 TreeView 节点右侧的加号来展开该节点时,该节点将被选中。我怎样才能避免这种情况?我希望能够在不更改所选节点的情况下展开节点(例如在 RegEdit.exe 中),并且仅在单击节点
我正在尝试设置一个 Treeview 对象,设置节点,然后更新控件以使值具有适当的格式。现在我有以下代码,当我设置一个控件时,它可以工作,但不是来自变量的控件。如何从变量设置本地控件? Private
如何将节点填充到作为另一个 treeview1 实例的 newtreeview1 中?添加到“newtreeview1”的节点应该在 treeview1 的第一个实例中可用? 例如;如果 treevi
我是一名优秀的程序员,十分优秀!