以编程方式在 Silverlight TreeView 上显示展开箭头

发布于 2024-08-03 19:59:22 字数 252 浏览 3 评论 0原文

我有一个 Silverlight TreeView 控件,当单击特定节点时,我会动态填充该控件。例如,我加载第一代(级别)节点,然后当用户单击其中一个节点时,我使用 Selected 事件填充该节点的子节点等。我从数据库发回一个 bool value 与每个节点值,指示新节点是否有子节点。

我想将展开箭头设置为显示在具有子节点的新节点前面,但问题是它的子节点还不会被填充。我想也许将 HasChild 设置为我的布尔值,但 HasChild 是只读的。任何建议将不胜感激。

I have a Silverlight TreeView control that I'm dynamically populating when a specific node is clicked. For example, I load the first generation (level) of nodes, then when the user clicks on one of the nodes, I use the Selected event to populate that node's children, etc, etc. I'm sending back from my database a bool value with each node value that indicates whether or not the new nodes have children nodes.

I am wanting to set the expand arrow to show in front of new nodes that have a child, but the catch is that its children will not be populated yet. I thought maybe setting the HasChild to my bool value, but HasChild is read-only. Any suggestions would be very much appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

孤芳又自赏 2024-08-10 19:59:23

只需在折叠时添加空白树视图项即可显示箭头。

但是,当用户展开时,清除该空白子级,并执行异步调用以获取真正的子级。

执行 GetChildrenAsync 调用时,将 UserState 设置为父树视图项或 id。

当它们到达时,当您找到刚刚将其 itemsource 设置为 e.Result 的父级时,UserState 应该是该父级 treeviewitem 或 id。

Just a add blank treeviewitem when it's collapsed just to show the arrow.

But when expanded by the user, clear that blank child, and do an async call to get the real children.

Set the UserState to the parent treeviewitem or id when doing the GetChildrenAsync call.

When they arrive, the UserState should be that parent treeviewitem or id, when you find that parent which you just set it's itemsource to the e.Result.

夜灵血窟げ 2024-08-10 19:59:23

如果您熟悉依赖项属性,则可以创建一个依赖项属性,该属性可由您在代码中设置并在 xaml 中获取,以便可以绑定到该属性。

这将允许您使用 ValueConverter 来呈现箭头的可见性。

If you're familiar with dependency properties, you could create a dependency property that would be settable by you in code and gettable in the xaml so it could be bound to.

This would allow you to use a ValueConverter to render the visibility of the arrow.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文