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

RadContextMenu in a RadGridView

1 Answer 157 Views
GridView
This is a migrated thread and some comments may be shown as answers.
jholt
Top achievements
Rank 1
jholt asked on 02 Dec 2010, 11:06 PM
I have a RadGridView bound to a collection of ObservableCollection<Foo>. I am trying to bind a Command from the view model to a RadContextMenu, but it would seem that no matter how you describe the RelativeSource to the DataContext, the RadContextMenu is only taking its binding from the ItemsSource of the RadGridView. The routing worked perfectly well in the past using ContextMenu.MenuItem and using the hack of binding to the PlacementTarget.Tag, but no longer works when I changed from MenuItem to RadMenuItem (which are much nicer). I have had to resort to RadMenuItem_Click since I can find no way of getting the binding to work.

<Controls:RadGridView ShowGroupPanel="False"
                                  Grid.Row="1"
                                  x:Name="radGridView"
                                  DockPanel.Dock="Top"
                                  DataContext="{Binding}"
                                  d:DataContext="{d:DesignData Source=../../DesignData/SampleBinderCollection.xaml}"
                                  ItemsSource="{Binding}"
                                  AutoGenerateColumns="False"
                                  IsSynchronizedWithCurrentItem="True"
                                  SelectedItem="{Binding DataContext.SelectedBinder,Mode=TwoWay, RelativeSource={RelativeSource AncestorType=Window}}"
                                  IsReadOnly="True"
                                  Tag="{Binding RelativeSource={RelativeSource AncestorType=Window}, Path=DataContext}"
                                  FrozenColumnCount="5"
                                  ShowColumnFooters="True"
                                  DataContextChanged="RadGridView_OnDataContextChanged">
                <Controls1:RadContextMenu.ContextMenu>
                    <Controls1:RadContextMenu>
                        <Controls1:RadMenuItem Header="Go to this invoice/transaction"
                                  Command="{Binding DataContext.OpenTransactionWindowFromInvoiceCommand, RelativeSource={RelativeSource AncestorType=Window}}"
                                               Click="RadMenuItem_Click">
                            <Controls1:RadMenuItem.Icon>
                                <Image Source="/Cornhouse;component/Images/NewCardHS.png"
                                       Width="16"
                                       Height="16" />
                            </Controls1:RadMenuItem.Icon>
                        </Controls1:RadMenuItem>
                     </Controls1:RadContextMenu>
                </Controls1:RadContextMenu.ContextMenu>
 
etc ....
 
The viemodel is simply
public class MyViewModel:INotifyPropertyChanged
{
    public ICommand OpenTransactionWindowFromInvoiceCommand {get etc}
    public ObservableCollection<Foo> Collection
     { 
       get{return _collection;}
       set{
_collection=value;
           RaisePropertyChanged("Collection");
}           
}

I would really appreciate some help with this.

Many thanks
Jeremy

1 Answer, 1 is accepted

Sort by
0
Konstantina
Telerik team
answered on 08 Dec 2010, 08:23 AM
Hi Jeremy,

Please refer to the following help article: http://www.telerik.com/help/wpf/radcontextmenu-how-to-use-commands-with-the-radcontextmenu.html, it should help you resolve your issue.

Please let us know if that helped and if you have further questions.

Kind regards,
Konstantina
the Telerik team
Browse the videos here>> to help you get started with RadControls for WPF
Tags
GridView
Asked by
jholt
Top achievements
Rank 1
Answers by
Konstantina
Telerik team
Share this question
or