This is a migrated thread and some comments may be shown as answers.

Commanding with TreeViewItems

2 Answers 181 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Scott Taylor
Top achievements
Rank 1
Scott Taylor asked on 24 Feb 2010, 11:24 PM
I'm trying to use the TreeViewItem in a RadOutlookBar to provide a navigation system for my app.

I'm trying to use Commands in a MVVM pattern to launch the views...

TreeViewItem lacks a Command property.. is there a way to do this?

2 Answers, 1 is accepted

Sort by
0
Miro Miroslavov
Telerik team
answered on 26 Feb 2010, 12:36 PM
Hello Scott Taylor,

We replay to your support ticket. I'm pasting this to allow others to it,a s well.

The TreeViewItems indeed do not have built-in support for commands.

If you are binding the TreeView you can use an ItemTemplate that contains buttons which have their command property set.

If the TreeView is  defined in Xaml you can assign the Header property of the TreeViewItem some kind of content that contains a button.

Sincerely yours,
Miro Miroslavov
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
k f
Top achievements
Rank 1
answered on 20 Mar 2010, 05:48 PM
Hello Scott,

You can build your own code to support commanding in any UI Element that doesn't natively support commanding.

I'm starting a community specifically for MVVM, Prism, MEF type discussions.

http://www.communityDevPatterns.com

In particularly, pull down the code from Lesson 4 Prism NW Databinding & Commands.

http://www.compositedevpatterns.com/list.php?category/48-Training-(Prism)

From that code, pull out the NSVMVVM assembly.  This assembly is mostly code from Sacha Barbers Cinch framework.  However, the code I use in it to implement commanding in elements that don't support it natively, I pulled from Jeff Brands training series.

http://www.slickthought.net/post/2009/05/28/Building-a-Composite-WPF-Application-Part-8-Custom-Commands-and-Non-Command-UI-Elements.aspx

Please check out CompositeDevPatterns.com.  I consulted with a couple of persons from Telerik and we thought it would be a good idea to have a central place to discuss MVVM, Prism etc.  The site is just being started so if you check it out and have any suggestions about the layout.  Have any thing you'd like to see a demo of, if I have time I'll consider adding it as a lesson.

Thanks.

P.S.  A sample of xaml wiring up a custom command to a Non-command UI element would look somethng like this using the code in the link I sent you.  

<telerik:RadComboBox MinWidth="150" Name="RCmbCustomers" IsTextSearchEnabled="True"
                nsvmvvm:CommandBehavior.TheCommandToRun="{Binding Path=SelectedCustomerCommand}"                       
                nsvmvvm:CommandBehavior.CommandParameter="{Binding ElementName=RCmbCustomers, Path=SelectedItem}"
                nsvmvvm:CommandBehavior.RoutedEventName="SelectionChanged"
                ItemsSource="{Binding Source={StaticResource CustomerModels}}"
                ItemTemplate="{StaticResource CustomerCmbTemplate}"
                SelectedValuePath="Id.DataValue"                
                telerik:TextSearch.TextPath="CompanyName.DataValue"                
                                 />
 
Tags
TreeView
Asked by
Scott Taylor
Top achievements
Rank 1
Answers by
Miro Miroslavov
Telerik team
k f
Top achievements
Rank 1
Share this question
or