数据集刷新后保持 TreeView 子树展开

发布于 2024-08-02 19:29:50 字数 283 浏览 2 评论 0原文

我正在使用 .Net RIA 服务的 7 月 '09 CTP,并将 Group=>Department=>Category 对象的对象绑定到树视图,然后让 hierarchialdatatemplate 呈现三种对象类型中的每一种。

我的最终目标是启用拖放功能,以便我可以快速编辑组列表 => 部门 => 类别,并以比以前更直观的方式更改它们各自的关系可用的。

我当前的问题是,当我执行 drop 命令并提交需要提交到数据上下文的更改时,我的树视图正在重绘并折叠叶子。有没有什么方法可以避免崩溃?

I'm working with the July '09 CTP of the .Net RIA services, and binding an object of Group=>Department=>Category objects to a treeview, and then having a hierarchialdatatemplate render each of the three object types.

What my end goal is for this will be to enable drag-n-drop functionality so that I can quickly edit my list of groups=>departments=>categories, and change their respective relationships in a more intuitive manner than what was previously available.

My current issue is that when I do the drop command, and submit the changes that need to be submitted to the data context, my treeview is redrawing, and collapsing the leaves. Is there a method by which I can use to avoid the collapse?

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

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

发布评论

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

评论(2

〗斷ホ乔殘χμё〖 2024-08-09 19:29:50

我发布这个答案纯粹是为了那些偶然发现这个帖子寻找答案的人。 (在 SL4 中完成)

您需要 2 个列表:

  1. 一个包含从服务接收到的数据(称为 sourceList),
  2. 另一个包含要显示的根条目(DisplayList),树视图绑定到该根条目。

您还必须确保您的 Load 操作的 LoadBehaviour 设置为 Merge。
例如:

    domainContext.Load(domainContext.GetEntityQuery(), LoadBehavior.MergeIntoCurrent, CallbackFunction, userState);

所以现在剩下的就是在每次更新后调用您的domainContext.Load,并在您的CallbackFunction中将您的sourceList替换为Web服务返回的新实体列表。由于显示列表的向下钻取条目依赖于关联和分层数据模板,因此它仍应在刚刚编辑的条目上展开。

注意如果您从头开始重建 DisplayList,树视图显然会重绘\折叠。

希望这对某人有帮助。

I'm posting this answer purely for those who stumble upon this thread looking for an answer. (was done in SL4)

you'll need 2 lists:

  1. one to contain the received data from the service (called sourceList)
  2. one to contain the root entries to display (DisplayList) to which your treeView is bound.

you also must make sure that your Load operation has its LoadBehaviour set to Merge.
for example:

    domainContext.Load(domainContext.GetEntityQuery(), LoadBehavior.MergeIntoCurrent, CallbackFunction, userState);

so all that remains now is to call your domainContext.Load after each update and in your CallbackFunction replace your sourceList with the new list of entities returned by the web service. Since your Display list's drill down entries relies on association and the hierarchical Data template it should still be expanded on the entry that was just edited.

Note if you rebuild the DisplayList from scratch the treeview would obviously redraw\collapse.

Hope this helps someone.
Jan

溺ぐ爱和你が 2024-08-09 19:29:50

我没有做过很多 Silverlight 工作,但据我所知,它的对象模型相当有限,因此执行此操作的某些事件/属性/方法可能不存在。但是您可以尝试自己保存/恢复状态...类似于以下伪代码:

private expandeds as collection();

tree.OnNodeExpand() {
    expandeds.add(tree.CurrentNode.key);
}

tree.OnNodeCollapse() {
    expandeds.remove(tree.CurrentNode.key);
}

tree.AfterBind() {
    for each key in expandeds {
        tree.FindNodeByKey(key).expanded = true;
    }
}

I've not done a lot of Silverlight work, but from what I've seen it has a pretty limited object model, so some of the events/properties/methods to do this may not be there. But you could try saving/restoring the state yourself... something akin to the following pseudo-code:

private expandeds as collection();

tree.OnNodeExpand() {
    expandeds.add(tree.CurrentNode.key);
}

tree.OnNodeCollapse() {
    expandeds.remove(tree.CurrentNode.key);
}

tree.AfterBind() {
    for each key in expandeds {
        tree.FindNodeByKey(key).expanded = true;
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文