Hello all
I have difficulty with RadContextMenu and particulary DataContext property.
I have a RadWindow ("mainWindow") who contain a RadTreeView. RadTreeView expose Items by HierarchicalDataTemplate, that this items who contains RadContextMenu.
My problem : DataContext of RadContextMenu is always DataContext of Item and I want the DataContext of the RadWindow.
I show you my XAML :
In this solution, I have an error : "cannot find ElementName=mainWindow" and I don't understand
I tried others methods to retrieve the DataContext (Tag in my StackPanel, ....)
Thank to you for help
PS : I am sorry for my english
I have difficulty with RadContextMenu and particulary DataContext property.
I have a RadWindow ("mainWindow") who contain a RadTreeView. RadTreeView expose Items by HierarchicalDataTemplate, that this items who contains RadContextMenu.
My problem : DataContext of RadContextMenu is always DataContext of Item and I want the DataContext of the RadWindow.
I show you my XAML :
<telerik:RadWindow x:Class="Vue.MainWindow" x:Name="mainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"><Grid x:Name="mainGrid"> <telerik:RadTreeView x:Name="radTreeView" Grid.Row="1" ItemsSource="{Binding TypeDatabases}" <telerik:RadTreeView.Resources> <HierarchicalDataTemplate DataType="{x:Type Modele:EntiteDatabase}" ItemsSource="{Binding Tables}"> <StackPanel Orientation="Horizontal" Height="25"> <Image Source="{Binding SourceIcone}" Stretch="Fill" Height="16"/> <TextBlock Text="{Binding Description}" TextAlignment="Left" VerticalAlignment="Center" /> <telerik:RadContextMenu.ContextMenu> <telerik:RadContextMenu InheritDataContext="False" DataContext="{Binding DataContext, ElementName=mainWindow}"> <telerik:RadMenuItem Header="Connexion" Command="{Binding OpenDatabase}" /> <telerik:RadMenuItem Header="Déconnexion" Command="{Binding CloseDatabase}" /> </telerik:RadContextMenu> </telerik:RadContextMenu.ContextMenu> </StackPanel> </HierarchicalDataTemplate> </telerik:RadTreeView.Resources> </telerik:RadTreeView></Grid></telerik:RadWindow>I tried others methods to retrieve the DataContext (Tag in my StackPanel, ....)
Thank to you for help
PS : I am sorry for my english