I have a DataGrid in a UserControl and I have added a ContextMenu to the DataGrid.
The XAML is as follows:
<sdk:DataGrid ItemsSource="{Binding Path=GridSource}">
<sdk:DataGrid.Columns>
<sdk:DataGridTextColumn Binding="{Binding Path=Name, Mode=OneWay}" Header="Name"/>
<sdk:DataGridTextColumn Binding="{Binding Path=Number, Mode=OneWay}" Header="Number"/>
</sdk:DataGrid.Columns>
<toolkit:ContextMenuService.ContextMenu>
<toolkit:ContextMenu Opened="ContextMenu_Opened">
<toolkit:MenuItem IsEnabled="False">
<toolkit:MenuItem.Icon>
<Image x:Name="menuIcon"/>
</toolkit:MenuItem.Icon>
</toolkit:MenuItem>
<toolkit:Separator />
<toolkit:MenuItem Header="View Agent Route" Click="AgentRoute_Click"/>
<toolkit:MenuItem Header="Live Track" Click="LiveTrack_Click"/>
</toolkit:ContextMenu>
</toolkit:ContextMenuService.ContextMenu>
</sdk:DataGrid>
If I set the source of the menuIcon Image in XAML using
<Image x:Name="menuIcon" Source="../../Assets/Images/user_green.png"/>
Then the icon is rendered fine but if I try to set it in the ContextMenu_Opened event handler using:
private void ContextMenu_Opened(object sender, RoutedEventArgs e)
{
menuIcon.Source = new BitmapImage(new Uri("../../Assets/Images/user_green.png", UriKind.Relative));
}
Nothing shows up, I don’t get an error or anything it just doesn’t show. I’ve used the same method to set an ImageSource (using the same actual *.png files) elsewhere in my application, any ideas what’s happening here?
Is this due to it being a ContextMenu? On a grid? I can’t figure out what’s going on.
I got this one working by using a ImageSourceConverter within the contextmenu_opened event.