This question already has an answer here:
I have a DataTemplate
in a ResourceDictionary
. Now I have a GroupBox
in the template, on which I want to use the MouseDown
event. But the ResourceDictionary
has no code behind
(as intended) and no link to the code behind of the file where I use the things from the dictionary.
How do I use this event?
i dont know if this applies to you but i had a similar case. I wanted to use MouseDown event on every labels of my ListBox. So here's what i did : I setted the ListBox.ItemTemplate to a ContentPresenter. Then i used MouseDown event on that ContentPresenter. I setted the ContentPresenter's ContentTemplate to the DataTemplate of my label and it worked well, thus separating my DataTemplate from my MouseDown event.
<ListBox
ItemsSource="{Binding}"
>
<ListBox.ItemTemplate>
<DataTemplate>
<ContentPresenter
ContentTemplate="{StaticResource myLabelTemplate}"
MouseDown="Event">
</ContentPresenter>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Sorry for my bad english ;)