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

Have a ContextMenu on a RadTree on specific constraints

9 Answers 76 Views
ContextMenu
This is a migrated thread and some comments may be shown as answers.
Julien
Top achievements
Rank 1
Julien asked on 25 Aug 2010, 10:20 AM
Hi!

I've a tree(representing a folder/file tree). I want to add a contextMenu only on "Folder" element

On all my "INodeElement", I've a property "IsFolder".

How to do that the contextMenu is only displayed when this property is true?

OR
How to have a different contextMenu depending of this property?

Thank you!

9 Answers, 1 is accepted

Sort by
0
Viktor Tsvetkov
Telerik team
answered on 26 Aug 2010, 01:30 PM
Hello Julien,

With our next minor release we will upload such an example on our QSF, but you can see it now from the attached sample project. It is not exactly the same scenario, but the same idea. If you have further questions feel free to ask.

All the best,
Viktor Tsvetkov
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
Julien
Top achievements
Rank 1
answered on 26 Aug 2010, 02:29 PM
It seems I cannot open it because it's a silverlight project and not wpf. I get errors about silverlight on load 
0
Viktor Tsvetkov
Telerik team
answered on 26 Aug 2010, 02:47 PM
Hi Julien,

Attached is the example in WPF. Examine it and tell me if it works for you.

Kind regards,
Viktor Tsvetkov
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
Julien
Top achievements
Rank 1
answered on 26 Aug 2010, 02:59 PM
Very interessant:

But: 
-How the template selector choose the correct template?
-We are trying to avoid all graphic code in the code behind, how can we create different menus like you do but in xaml side?
0
Viktor Tsvetkov
Telerik team
answered on 26 Aug 2010, 05:25 PM
Hi Julien,

- In the example that I sent to you the template selector chooses the template based on the type of the file. You can find more info about ItemTemplateSelector here.
- In this case you can define the ItemContainerStyle property of the RadTreeView this way:
<Style x:Key="treeViewStyle"
                   TargetType="telerik:RadTreeViewItem">
                <Style.Triggers>
                    <DataTrigger Binding="{Binding Path=IsFolder}"
                                 Value="True">
                        <Setter Property="telerik:RadContextMenu.ContextMenu">
                            <Setter.Value>
                                <!--Your custom context menu-->
                                <telerik:RadContextMenu />
                            </Setter.Value>
                        </Setter>
                    </DataTrigger>
                </Style.Triggers>
            </Style>
If you need more help I will be glad to further assist you.

Best wishes,
Viktor Tsvetkov
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
Julien
Top achievements
Rank 1
answered on 27 Aug 2010, 10:22 AM
It seems great,

But I've some event, and I have to create EventSetter. For my "Opened"  on RadContextMenu, there is no problem, but I've "Click" event on each RadMenuItem. How to set a different handler for each RadMenuItem with an EventSetter?

And it seems I cannot reach anymore my menu from the code behind by its name:
RadTreeViewItem radItem = uxContextualMenu.GetClickedElement<RadTreeViewItem>();
0
Viktor Tsvetkov
Telerik team
answered on 31 Aug 2010, 04:31 PM
Hello Julien,

Instead of setting a different event handler you can set a different command on each RadMenuItem. Could you please examine the modified project and tell me if it works for you?

Best wishes,
Viktor Tsvetkov
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
Julien
Top achievements
Rank 1
answered on 01 Sep 2010, 06:34 AM
it seems this is what I need.

But why it doesn't show the menu on any node this isn't a leaf? in my case, it's a recursive tree, so I need to have this menu on every node
0
Viktor Tsvetkov
Telerik team
answered on 01 Sep 2010, 08:24 AM
Hi Julien,

In this sample project the context menu is shown only if the item has a property IsCodeBehindFile. In your case you will set the trigger on the IsFolder property and every item will have such property, so you will have your custom context menu on every item.

All the best,
Viktor Tsvetkov
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
Tags
ContextMenu
Asked by
Julien
Top achievements
Rank 1
Answers by
Viktor Tsvetkov
Telerik team
Julien
Top achievements
Rank 1
Share this question
or