Reputation: 4782
in my Silverlight 4 application, I have a listbox for which I created a nice DataTemplate. This DataTemplate contains some buttons, for which I want to handle events. So I assigned the event on the template:
<DataTemplate>
<Grid>
<Button x:Name="myB" Click="myB_Click" />
</Grid>
</DataTemplate>
In the UserControl that contains the listbox that uses this template I have the eventhandler that handles the myB_Click.
As long I have the template assigned directly within the listbox, everything works fine:
<ListBox ...>
<ListBox.ItemTemplate>
<DataTemplate>
...
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
But when I outsource the DataTemplate to a ResourceDirectory, I get a runtime parser-error when adding an item to the listbox
Kategorie: ParserError
Message: Error assigning to Property 'System.Windows.Controls.Button.Click'.
Any idea, what might cause this?
Thanks in advance,
Frank
Upvotes: 0
Views: 812
Reputation: 7601
if you put it in a resource dictionary then it can't find the event handler since your resource dictionary doesn't have code behind.
either you (a) don't put that part in the ResourceDictionary and keep it in your xaml or (b) add code behind to your resource dictionary
Upvotes: 2