I have a ListBox which binds to a bunch of items, and the listbox uses a DataTemplate to determine how each item is rendered
<Window x:Class="DataTemplateExample.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Window.Resources>
<DataTemplate x:Key="listBoxDataTemplate">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Age}" ></TextBlock>
<TextBox Background="Transparent" Text="{Binding Name}" ContextMenu="{x:Null}"></TextBox>
</StackPanel>
</DataTemplate>
</Window.Resources>
<Grid>
<StackPanel>
<ListBox ItemTemplate="{StaticResource listBoxDataTemplate}" ItemsSource="{Binding Strings}">
</ListBox>
<TextBox ContextMenu="{x:Null}">Some Cool Text</TextBox>
</StackPanel>
</Grid>
</Window>
Above is a simple reproduction.
Note that in the TextBox that is in the datatemplate I set the ContextMenu to null, yet when you right click it at runtime the menu still pops up.
The TextBox at the bottom (not in a datatemplate) reacts as I would expect them both to.
Any ideas?
I'll put together a XAMLPad friendly version too.
I'll put together a XAMLPad friendly version too.