Search code examples
windows-8microsoft-metrosemantic-zoom

It is possible to select a ListView item with a single tap or left click?


I am developing a Windows 8 metro application that uses semantic zoom in the following way:

  • The zoomed in view contains a ListView with complex controls that allow for user interaction (by using TextBox and Button controls), therefore this ListView has IsItemClickEnabled="False". The user must trigger the zoomed out view manually.

  • The zoomed out view contains another ListView which displays a simple list that displays some status information for the controls in the zoomed in view. The ItemsSource property of this ListView is populated dinamically with plain objects that are created in the moment that the view is made active. This ListView has IsItemClickEnabled="True".

What do I want:

When the user taps or clicks on an item in the zoomed out view, the zoomed in view should activate and the control matching the clicked item should be made visible (the zoomed in ListView allows scrolling, so the control could be hidden). I know how to do this as long as the SelectionChanged event is triggered when a item is clicked.

What happens instead:

When the user taps or clicks on an item in the zoomed out view, the zoomed in view activates automatically and no SelectionChanged event is triggered. However, it works fine when using right click or Ctrl+click instead.

So, my question is:

Is there any way to make a ListView trigger the SelectionChanged event on item tap or left click, in addition to right click and Ctrl+click? If not, how can I detect the tap or left click?

Thank you very much!


Solution

  • I found out the solution. I must control the Tapped event of the control that is inside the defined DataTemplate for the list, NOT the event of the ListView itself:

    <SemanticZoom...>
        <SemanticZoom.ZoomedOutView>
            <ListView ...>
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <Border ... Tapped="Item_Tapped">
    

    And in the Item_Tapped method, I just cast sender to FrameworkElement and look at its DataContext.