开发者

Hierarchical data with XML and Treeview

I'm making a UI where the user can add and store links 开发者_如何学Cto 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.


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)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜