Is there a click behavior for a list?
Asked Answered
D

2

5

I have a list view, on a panoramic control. I've also created an event for MouseLeftButtonUp however I find that when scrolling between the panorama items the MousLeftButtonUp is triggering (it makes sense why but it is unexpected from a user perspective).

Is there any way to create a click event for a list? Or add a behavior that simulates that?

Diao answered 9/1, 2011 at 5:7 Comment(1)
FYI WP7 use Silverlight 3, not 4Asarum
B
8

Checkout the Tap gesture from the Gesture service that's part of the toolkit.

WP7 Tip of the Day: Silverlight Toolkit: Gestures

    <ListBox Height="100" HorizontalAlignment="Left" Margin="12,186,0,0" Name="listBox1" VerticalAlignment="Top" Width="460" >
        <Controls:GestureService.GestureListener>
            <Controls:GestureListener Tap="GestureListener_Tap">
            </Controls:GestureListener>
        </Controls:GestureService.GestureListener>
        <ListBoxItem Content="1"/>
        <ListBoxItem Content="2"/>
        <ListBoxItem Content="3"/>
        <ListBoxItem Content="4"/>
    </ListBox>

and

public void GestureListener_Tap(object sender, GestureEventArgs e) {
    System.Diagnostics.Debug.WriteLine("tap");
}
Briant answered 9/1, 2011 at 5:18 Comment(1)
I had to use <toolkit:GestureService.GestureListener> <toolkit:GestureListener Tap="GestureListener_Tap"/> but it works perfectlyDiao
D
0

The listbox should already accept contact, so you can just fire the SelectionChanged event

Dunedin answered 9/1, 2011 at 5:30 Comment(1)
This is true, however it won't fire on a second tap if there is no change in selection. This is usually what prompts people to go looking for other options like adding buttons, checking mouseleftbuttonup, etc.Briant

© 2022 - 2024 — McMap. All rights reserved.