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

Prism + ContextMenu for TreeView

1 Answer 195 Views
This is a migrated thread and some comments may be shown as answers.
Ruslan Devyatko
Top achievements
Rank 1
Ruslan Devyatko asked on 13 Aug 2010, 09:01 AM

Hello everyone!

I'm using RadOutlookBar as a region in my Prism application. RadOutlookBarItems are being dynamically loaded to that region as its views. All RadOutlookBarItems are the same:

<telerikNavigation:RadOutlookBarItem x:Name="outlookBarItem">
<telerikNavigation:RadTreeView Name="NavigaionTree" SelectionMode="Single" ItemTemplate="{StaticResource Section}"
ItemsSource="{Binding Path=AppNavigationItems}" 
SelectedItem="{Binding Mode=TwoWay, Path=CurrentAppNavigationItem}"
<telerikNavigation:RadContextMenu Name="contextMenu">
<telerikNavigation:RadMenuItem Header="Развернуть" Name="ExpandButton" Click="ExpandButtonClick"/>
<telerikNavigation:RadMenuItem Header="Свернуть" Name="ReduceButton" Click="ReduceButtonClick"/>
<telerikNavigation:RadMenuItem Header="Открыть" Name="NewTabButton" Click="NewTabButtonClick"/>
<telerikNavigation:RadMenuItem Header="Открыть в фоновой вкладке" Name="ShadowTabButton" Click="ShadowTabButtonClick"/>
<SolidColorBrush Color="White"/>

During runtime I want to manipulte with RadMenuItms in every view:

private void NavigaionItemMouseDown(object sender, MouseButtonEventArgs e)
            if (sender is RadTreeViewItem)
                var treeViewitem = sender as RadTreeViewItem;
                treeViewitem.IsSelected = true;
                e.Handled = true;
                if (treeViewitem.HasItems)
                    this.NewTabButton.Visibility = Visibility.Collapsed;
                    this.ShadowTabButton.Visibility = Visibility.Collapsed;
                    this.ExpandButton.Visibility = Visibility.Visible;
                    this.ReduceButton.Visibility = Visibility.Visible;
                    this.ExpandButton.IsEnabled = !treeViewitem.IsExpanded;
                    this.ReduceButton.IsEnabled = treeViewitem.IsExpanded;
                    this.ExpandButton.Visibility = Visibility.Collapsed;
                    this.ReduceButton.Visibility = Visibility.Collapsed;
                    this.NewTabButton.Visibility = Visibility.Visible;
                    this.ShadowTabButton.Visibility = Visibility.Visible;

public AppNavigationView()

                MouseRightButtonDownEvent, new MouseButtonEventHandler(NavigaionItemMouseDown), false);

But unfortunately my logic works well only in the first RadOutlookBarItem. It also works for every other
RadOutlookBarItem, but the result PopUp still consists of 4 items.
Please help me solve this "miracle".
Thank you in advance.

1 Answer, 1 is accepted

Sort by
Miro Miroslavov
Telerik team
answered on 18 Aug 2010, 02:19 PM
Hello Ruslan Devyatko,

I guess that you should find the name of the MenuItems using the FindName() method(for example 
treeViewitem.ParentTreeView.FindName("ExpandButton") and then change it's visibility.
Also can you give us some more information - do you get the Right mouse down correctly? If so you collapse the menuitems, but they still are visible?

Other thing you can do is to declare this ContextMenu in your resources and attach it to the TreeView using StaticResource. And after that in the handler get the ContenxMenu from the resources and find it's MenuItems using FindName("") method.

Hope this will help you.

All the best,
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
Asked by
Ruslan Devyatko
Top achievements
Rank 1
Answers by
Miro Miroslavov
Telerik team
Share this question