Handle OnClick Event in ListBox on Silverlight for Windows Phone 7





0/5 (0 vote)
Handle OnClick event in ListBox on Silverlight for Windows Phone 7.
Generally on Windows Phone 7 using Silverlight You will use ListBox templates like this one
<ListBox Margin="0,0,-12,0" ItemsSource="{Binding Items}" >
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Margin="0,0,0,17"
MouseLeftButtonDown="StackPanel_MouseLeftButtonDown">
<Image Height="150" Width="150"
Source="{Binding ImageSource}" Stretch="UniformToFill" />
<StackPanel Width="311">
<TextBlock Text="{Binding LineOne}"
TextWrapping="Wrap"
Style="{StaticResource PhoneTextExtraLargeStyle}"/>
<TextBlock Text="{Binding LineTwo}" TextWrapping="Wrap"
Margin="12,-6,12,0" Style="{StaticResource PhoneTextSubtleStyle}"/>
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
But on touch based platform such as Windows Phone 7, MouseLeftButtonDown
will trigger event, even if You try scroll ListBox content. Another
approach is to use ManipulationCompleted
event. Event arguments have property named
IsTapEvent
, but in latest Silverlight SDK this property is declared as
Protected
. So You can see it in debugger at runtime, but cannot use in code.
What You can do is subscribe to ManipulationCompleted
event, and check e.TotalManipulation
for
Scale
and Transform
properties equals zero.
private void StackPanel_ManipulationCompleted(object sender, ManipulationCompletedEventArgs e)
{
var zero = new Point(0,0);
if( e.TotalManipulation.Scale == zero && e.TotalManipulation.Translation == zero )
MessageBox.Show("gotcha!");
}