I have a Windows Phone 7 ListBox
that binds to a list of integers. I am using the default MVVM Light template, so there is a ViewModel
class that
This is a known problem with Silverlight 3
. To work around this, wrap your DataTemplate
in a UserControl
:
<UserControl x:Class="SilverlightApplication.MyUserControl">
<Button Content="{Binding}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<cmd:EventToCommand Command="{Binding ElementName=ContentGrid, Path=DataContext.TestCommand}"
CommandParameter="{Binding}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
</UserControl>
And use it instead:
<ListBox ItemsSource="{Binding MyData}">
<ListBox.ItemTemplate>
<DataTemplate>
<local:MyUserControl />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>