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