I have a ResourceDictionary that contains a <DataTemplate>
with a <TextBox>
in it. The problem is how to use a binding to connect the ContextMenuOpening
event of the TextBox
. I have tried creating a DependencyProperty through DependencyProperty.Register
with a name that matches the Binding in the ContextMenuOpening
event, but at runtime the error is:
A 'Binding' cannot be set on the 'AddContextMenuOpeningHandler' property of type 'TextBox'. A 'Binding' can only be set on a DependencyProperty of a DependencyObject.
ResourceDictionary XAML:
<DataTemplate>
<Grid>
<TextBox ContextMenuOpening="{Binding ??WHAT GOES HERE?? }" />
</Grid>
</DataTemplate>
Is what I'm trying to do even possible because of the XAML being in the ResourceDictionary rather than in the XAML of a UserControl?