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

ContextMenu For Expand/Collapse/Find

5 Answers 155 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Software
Top achievements
Rank 1
Software asked on 04 Nov 2011, 09:20 AM

Hello,
I would like to implement a context menu for all my application treeviews that allow users to ExpandAll, CollapseAll and Find text into nodes.
 For example, manage a style in the ressource dictionnary that looks like this :

<Style x:Key="StyleTreeViewWithContextMenu" TargetType="{x:Type telerik:RadTreeView}">
   <Setter Property="ContextMenu">
       <Setter.Value>
           <telerik:RadContextMenu>
               <telerik:RadMenuItem Header="Déployer tout"   />
               <telerik:RadMenuItem Header="Replier tout" />
               <telerik:RadMenuItem Header="Trouver" />
           </telerik:RadContextMenu>
      </Setter.Value>
   </Setter>
</Style>

How can I implement the actions of menuItems in order to apply this style on my treeviews?

Could you put me on track ?

Thanks in advance.
Olivier.

5 Answers, 1 is accepted

Sort by
0
Tina Stancheva
Telerik team
answered on 09 Nov 2011, 01:09 PM
Hi Olivier,

I attached a sample project and I hope it will get you started on your task. Please examine the solution and let me know if it helps or if we can further assist you.

Kind regards,
Tina Stancheva
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Software
Top achievements
Rank 1
answered on 21 Nov 2011, 10:01 AM
Hi Tina,
Sorry for the loooong response time ...
Thank you for this example, it meets my needs but I tried to implement it in my application and I did not come to call the commands by the delegatecommands.
The sources of my treeviews are collections of objects EntityFramework and I can not reference the namespace Telerik.Windows.Controls in my DAL EntityFramework(please consider that I am not very experienced in WPF development).
Perhaps it is easier to move more on the development of a user control (like a toolbar or ContextMenu) bind the treeview with the call method of the treeview ?

Thanks.
Olivier.
0
Tina Stancheva
Telerik team
answered on 24 Nov 2011, 10:41 AM
Hello Olivier,

Thank you for getting back to us. In this case you can follow two approaches.

You can either create a wrapper class for the EntityFramework objects where to add the DelegateCommand definition, or you can attach a RadMenuItem.ClickEvent as I demonstrated in the sample project - the 'search' context menu option is implemented in the code-behind file of the Window that hosts the RadTreeView control. An event handler is defined for the Click event of the RadMenuItem. You can use this event handler to create the logic that should be implemented by each RadMenuItem.

Do you think you can use one of those approaches is your application or am I missing something?

Greetings,
Tina Stancheva
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Software
Top achievements
Rank 1
answered on 01 Dec 2011, 12:05 PM
Tina,
I take the second way, and no problem to implement Expand/collapse by calling the treeview's methods, but little more complex for the "find method" implementation :
I want this option in all  treeviews in the application, so I make a class "treeviewtoolbox" for attach the context menu, but I dont know in advance wich kind of model is in itemsources of the treeviews, so how can i make a generic void to find text in a treeview ?
Thanks
Olivier.
0
Petar Mladenov
Telerik team
answered on 06 Dec 2011, 01:09 PM
Hi Olivier,

If you wish to avoid working with the ViewModels and you wish only to find particular RadTreeViewItem (not to filter the TreeView), you can iterate over the RadTreeViewItems (note that they have to be already generated).
Please check out this help article and let us know if it might help you.

Kind regards,
Petar Mladenov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
TreeView
Asked by
Software
Top achievements
Rank 1
Answers by
Tina Stancheva
Telerik team
Software
Top achievements
Rank 1
Petar Mladenov
Telerik team
Share this question
or