Как программно добавить контекстное меню, где Conrol (DepedencyObject) создается в шаблоне данных в xaml?
XAML:
<ListBox x:Name="sampleListBox"
ItemsSource="{Binding SomeCollection}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel x:Name="sp">
<TextBlock Text="{Binding Value}" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Код:
void Initilize()
{
ContextMenu cm = new ContextMenu();
cm.Items.Add(new MenuItem());
ContextMenuService.SetContextMenu(
// I am not geting the DepedencyObject as a parameter and
// depedency Object has to passed.
// My Qyestion is how to get the Stack pannel here.
, cm);
}