I have a gridView that is part of a DataTemplate for a TabControl. One of my columns has a cell edit template that contains a textbox with a context menu. I need to bind the context menu to a collection on my viewmodel. but because it's not part of the virtual tree, I couldn't define the source in xaml. I managed to get it working by handling the Opened event and setting the DataContext of the contextmenu to the same as the user control. It all worked well, but then I ran into some trouble.
Elsewhere in code, I need to be able to call GridView.CommitEdit(), so I moved the DataTemplate code for the TabControl to a new user control to be able to call this method. Doing this however broke my code that sets the DataContext of the Context menu, because the DC of the new user control is not the view model...it is the entityObject to which its bound since it's a DataTemplate.
Is there anyway I can call the CommitEdit method from code-behind if the grid view is defined in a DataTemplate? Or possibly define the context menu elsewhere so that the datacontext can be set on it?
Elsewhere in code, I need to be able to call GridView.CommitEdit(), so I moved the DataTemplate code for the TabControl to a new user control to be able to call this method. Doing this however broke my code that sets the DataContext of the Context menu, because the DC of the new user control is not the view model...it is the entityObject to which its bound since it's a DataTemplate.
Is there anyway I can call the CommitEdit method from code-behind if the grid view is defined in a DataTemplate? Or possibly define the context menu elsewhere so that the datacontext can be set on it?