Have a ContextMenu on a RadTree on specific constraints

10 posts, 0 answers
  1. Julien
    Julien avatar
    236 posts
    Member since:
    Jul 2010

    Posted 25 Aug 2010 Link to this post

    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!
  2. Viktor Tsvetkov
    Admin
    Viktor Tsvetkov avatar
    382 posts

    Posted 26 Aug 2010 Link to this post

    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
  3. UI for WPF is Visual Studio 2017 Ready
  4. Julien
    Julien avatar
    236 posts
    Member since:
    Jul 2010

    Posted 26 Aug 2010 Link to this post

    It seems I cannot open it because it's a silverlight project and not wpf. I get errors about silverlight on load 
  5. Viktor Tsvetkov
    Admin
    Viktor Tsvetkov avatar
    382 posts

    Posted 26 Aug 2010 Link to this post

    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
  6. Julien
    Julien avatar
    236 posts
    Member since:
    Jul 2010

    Posted 26 Aug 2010 Link to this post

    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?
  7. Viktor Tsvetkov
    Admin
    Viktor Tsvetkov avatar
    382 posts

    Posted 26 Aug 2010 Link to this post

    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
  8. Julien
    Julien avatar
    236 posts
    Member since:
    Jul 2010

    Posted 27 Aug 2010 Link to this post

    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>();
  9. Viktor Tsvetkov
    Admin
    Viktor Tsvetkov avatar
    382 posts

    Posted 31 Aug 2010 Link to this post

    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
  10. Julien
    Julien avatar
    236 posts
    Member since:
    Jul 2010

    Posted 01 Sep 2010 Link to this post

    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
  11. Viktor Tsvetkov
    Admin
    Viktor Tsvetkov avatar
    382 posts

    Posted 01 Sep 2010 Link to this post

    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
Back to Top
UI for WPF is Visual Studio 2017 Ready