Win RT Xaml GridView:拖动选择多个项目 [英] Win RT Xaml GridView: Drag select multiple items

查看:92
本文介绍了Win RT Xaml GridView:拖动选择多个项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过用鼠标悬停在GridView中的多个项目上来选择它们(如绘图).我试图通过PointerEntered事件来实现这一点,但是我无法从代码中更改选择.有没有一种方法可以实现自定义选择模式?

I'm trying to select multiple items in a GridView by hovering over them with pressed mouse (like drawing). I tried to achieve this with the PointerEntered event but I'm unable to change the selction from code. Is there a way to implement a custom selection mode?

这对我不起作用,因为我无法在Win RT XAML中使用Style.Triggers: https://stackoverflow.com/a/2886223/5739170

This didn't work for me because I can't use Style.Triggers in Win RT XAML: https://stackoverflow.com/a/2886223/5739170

推荐答案

您将必须继承gridview控件并重写PrepareContainerForItemOverride方法:

You will have to inherit the gridview control and override the PrepareContainerForItemOverride method:

代码:

public class MyGridView : GridView
{

    protected override void PrepareContainerForItemOverride(DependencyObject element, object item)
    {
        (element as GridViewItem).PointerMoved += MyGridView_PointerMoved;

        base.PrepareContainerForItemOverride(element, item);
    }

    private void MyGridView_PointerMoved(object sender, PointerRoutedEventArgs e)
    {

 //your logic for setting the isselected
         (sender as GridViewItem).IsSelected = true;
    }
}

这篇关于Win RT Xaml GridView:拖动选择多个项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆