ListView Item Selection Windows Store

2019-08-10 02:22发布

I want a ListView to behave like this:

With mouse Input:

  • Left Click -> Item click event handler gets executed, but should not display it as "selected"
  • Right Click -> Item gets selected

With touch Input:

  • Single Tap -> equivalent to left click
  • Swipe Down -> equivalent to right click

I have played around with various of the events and settings but cant seem to get it to work right.

2条回答
手持菜刀,她持情操
2楼-- · 2019-08-10 02:39

This could help you with the mouseclicks

 private void MainForm_MouseDown(object sender, MouseEventArgs e)
    {
        if (e.Button == MouseButtons.Left)
            method()
        if (e.Button == MouseButtons.Right)
            set selection = false
            method()
    }

and for the handle of the touch i hope this helps

http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh465387.aspx

查看更多
Melony?
3楼-- · 2019-08-10 02:50

In other words, you want your listview to behave like the Windows Start screen? This one was brutal for me to figure out - the mouse part was easy, but the touch part not so much. The solution turns out to be pretty easy. You just have to enable the right options for your listview. Here's the xaml for mine:

<ListView
        x:Name="itemListView"
        SelectionMode="Extended"
        IsSwipeEnabled="True"
        IsItemClickEnabled="True"
        ItemClick="ItemView_ItemClick"
        />

Sorry, I haven't figured how to get code to highlight in StackOverflow yet.

查看更多
登录 后发表回答