DataContext of RadContextMenu

3 posts, 0 answers
  1. Arnaud
    Arnaud avatar
    28 posts
    Member since:
    Jan 2013

    Posted 10 Jul 2013 Link to this post

    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 :
    <telerik:RadWindow x:Class="Vue.MainWindow" x:Name="mainWindow"              xmlns=""
    <Grid x:Name="mainGrid">
       <telerik:RadTreeView x:Name="radTreeView" Grid.Row="1" ItemsSource="{Binding TypeDatabases}"
                      <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 InheritDataContext="False" DataContext="{Binding DataContext, ElementName=mainWindow}">
                                            <telerik:RadMenuItem Header="Connexion" Command="{Binding OpenDatabase}" />
                                            <telerik:RadMenuItem Header="Déconnexion" Command="{Binding CloseDatabase}" />
    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
  2. Rosen Vladimirov
    Rosen Vladimirov avatar
    640 posts

    Posted 15 Jul 2013 Link to this post

    Hi Arnaud,

    You are not able to use Binding for DataContext in HierarchicalDataTemplate. I've prepared a simple project, which is based on your requirements. Please find it attached and inform us if you have any problems or concerns.

    Rosen Vladimirov
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  3. Arnaud
    Arnaud avatar
    28 posts
    Member since:
    Jan 2013

    Posted 17 Jul 2013 Link to this post

    Thanks for reply
    I tried to have a DataContext per HierarchicalDataTemplate. 
    I will apply one DataContext for my RadTreeView and play with Visibility for displaying commands depending object selected.
    Thanks again
Back to Top