You can use commanding to achieve this. Have the Button
s in the DataTemplate
execute specific Command
s:
<Button Command="{x:Static MyCommands.SomeCommand}"/>
Then have each view that uses that DataTemplate
handle the Command
:
<UserControl>
<UserCommand.CommandBindings>
<CommandBinding Command="{x:Static MyCommands.SomeCommand}"
Executed="_someHandler"/>
</UserCommand.CommandBindings>
</UserControl>
EDIT after comments: Once you have created a code-behind for your ResourceDictionary
as per these instructions, you can simply connect events in the usual fashion:
In MyResources.xaml
:
<ListBox x:Key="myListBoxResource" ItemSelected="_listBox_ItemSelected"/>
Then in MyResources.xaml.cs
:
private void _listBox_ItemSelected(object sender, EventArgs e)
{
...
}