使用 XML 和 Treeview 的分层数据

发布于 2024-12-03 03:39:35 字数 504 浏览 1 评论 0原文

我正在制作一个用户界面,用户可以在其中添加和存储他们最喜欢的 YouTube 视频的链接。与浏览器中的收藏夹非常相似,但仅适用于 Youtube 视频。

我希望链接显示在树视图中,以便可以将它们编入类别和子文件夹等。有点像这样:

Videos
|---Music Videos
      |---Music video 01
      |---Music video 02
      |---Music video 03
|---TV Shows
      |---TV show 01
      |---TV show 01

我目前最苦恼的是弄清楚用户如何存储这些数据用户界面关闭后。我一直在研究 xml 绑定,但我似乎无法创建一个看起来可以与树视图一起正常工作的像样的 xml 模式。

另外,我将如何存储 URL 和视频名称,但让树视图仅显示名称?

我将非常感谢任何有关解决此问题的最佳方法的指示。有更好的办法吗?这一切都非常令人困惑。

非常感谢。

I'm making a UI where the user can add and store links to their favourite Youtube videos. Very similar to a favourites folder in a browser, but just for Youtube videos.

I want the links displayed in a treeview, so that they can be catalogued into categories and sub-folders, etc. Sort of like this:

Videos
|---Music Videos
      |---Music video 01
      |---Music video 02
      |---Music video 03
|---TV Shows
      |---TV show 01
      |---TV show 01

What I'm struggling with most at the moment, is working out how the user can store this data once the UI has closed. I've been looking into xml binding, but I can't seem to create a decent xml schema that seems to work properly with the treeview.

Also, how would I go about storing the URL along with the video name, but have the treeview display only the name?

I'd be very grateful for any pointers as to the best way to go about this. Is there a better way? It's all very confusing.

Thanks very much.

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

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

发布评论

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

评论(1

月亮是我掰弯的 2024-12-10 03:39:35

好的数据架构是一个不平凡的问题,我只能提供我的一些想法,但不能保证它们都是好主意。

首先不建议直接使用 XML 数据,如果您尝试做更复杂的事情,它会变得非常不方便。

您可以将数据序列化为 XML,但您应该意识到它的局限性和副作用,在尝试比较各种序列化方法的 SO 上可以找到一些问题,您可能需要寻找其他格式的数据可能更合适。例如,XML 的两个方面非常明显:

  • 由于标签和标签导致的巨大文件大小开销。和基于文本的数据
  • 与二进制序列化不同,数据或多或少是人类可读和透明的。

无论如何,我都会使用数据库或普通对象模型并将其序列化/反序列化以进行存储。

如果您想允许子类别,您可能需要使用复合模式,然后您可以对象 VideoCategory,均实现接口 IVideoComposite,其中 Category 有一个属性例如,ObservableCollection 类型的 Children

然后,您可以使用隐式类型数据模板(HierarchicalDataTemplatefor Category)来在 TreeView 中创建项目。 (对于 Category 之一,您将把 ItemsSource 绑定到 Children

Good data architecture is a non-trivial issue, i can just offer some thoughts of mine but cannot guarantee that they are all a good idea.

Firstly would not recommend working directly with XML data, it gets very inconvenient if you try to do more complex things.

You can serialize your data to XML, but you should be aware of its limitations and side-effects, there are questions to be found here on SO which try to compare the various methods of serialization, you might want to look for those as other formats might be more suitable. Two aspects of XML are quite apparent for example:

  • Huge file-size overhead due to the tags & and text-based data
  • Unlike binary serialization the data is more or less human readable and transparent

In any case i would use a database or a normal object model and serialize/deseriale that for storage.

If you want to allow sub-categories you may want to use a composite pattern, you then can have an object Video and Category, both implementing the interface IVideoComposite, where Category has a property Children of type ObservableCollection<IVideoComposite> for example.

You then can use implicitly typed datatemplates (a HierarchicalDataTemplate for Category) to create the items in your TreeView. (For the one of Category you will then bind the ItemsSource to Children)

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