How do I use SoapBox Core to make a TreeView using the MVVM architecture (extensible or not)?

asked 11 Sep '10, 21:02

Scott%20Whitlock's gravatar image

Scott Whitlock ♦♦
696262833
accept rate: 50%


Version 2010.09.11 introduces the ITreeViewItem interface and the AbstractTreeViewItem and AbstractTreeView base classes. You can use these to build ViewModel objects for TreeViewItem and TreeView WPF objects, respectively.

Here's a tree with an extensible list of items:

class MyTree : AbstractTreeView, IPartImportsSatisfiedNotification
{
    [ImportMany("my contract", typeof(ITreeViewItem))]
    private IEnumerable<ITreeViewItem> topLevelNodes { get; set; }

    [Import(SoapBox.Core.Services.ExtensionService, typeof(IExtensionService))]
    private IExtensionService extensionService { get; set; }

    public void OnImportsSatisfied()
    {
        Items = extensionService.Sort(topLevelNodes);
    }
}

Your top level nodes can then import more levels of nodes, etc. You'll need to export MyTree and import it somewhere as a property on a ViewModel object. Then in the View of that ViewModel object, you stick a ContentControl in the Xaml and hook it up like this:

<!-- Tree -->
<ContentControl
    x:Name="myTreeControl"
    Content="{Binding MyTreeProperty}">
</ContentControl>

AbstractTreeView has a DataTemplate that will apply a TreeView to the ViewModel.

link

answered 11 Sep '10, 21:15

Scott%20Whitlock's gravatar image

Scott Whitlock ♦♦
696262833
accept rate: 50%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×6
×2
×1

Asked: 11 Sep '10, 21:02

Seen: 2,524 times

Last updated: 11 Sep '10, 21:15

powered by OSQA