【问题标题】:DragDropManager How to prevent from adding incoming element to list?DragDropManager 如何防止将传入元素添加到列表中?
【发布时间】:2014-03-03 03:18:51
【问题描述】:

目前我的页面由两个并排的网格组成,每个网格绑定一个列表,说 GridA 绑定 ListAGridB 绑定列表B

两个网格都实现了Telerik DragDropManager。在大多数情况下一切正常,用户可以简单地将元素从 GridA 拖放到 GridB 以及 ListAListB 会相应地反映。

现在我正在尝试对 GridB 进行检查,以便每当用户从 GridA 拖动一个元素时,该元素是否存在于 GridB >,该元素不会被添加。

我注意到我可以在 GridB 上实现drop 函数,如下所示:

<telerik:RadGridView 
    ItemSource="{Binding ListB}" 
    DataContext="{Binding [someViewModel]}" 
    Drop="abc_Drop" 
    DataLoaded="abc_DataLoaded"
    x:Name="GridB">

下面将是我的drop 函数:

private void abc_Drop(object sender, System.Windows.DragEventArgs e)
{
   var selectedItem = (T)GridA.SelectedItem;
   List<T> x = someViewModel.ListB; 
}

为了调查,我在abc_Drop 方法上放了一个断点。我发现,当我执行abc_Drop 方法时,someViewMode.ListB.Count() 仍然返回0,但一旦完成,someViewModel.ListB.Count() 返回1。因此我的问题是,我应该在哪里进行检查并阻止有条件地添加到列表中?在drop方法之后会执行什么?

【问题讨论】:

    标签: c# wpf drag-and-drop grid telerik


    【解决方案1】:

    我自己找到了答案。

    private void abc_Drop(object sender, System.Windows.DragEventArgs e){
    
        e.Handled = true;
        var selectedItem = (T)GridA.SelectedItem;
        if( /*condition*/ ){
            ListB.Add(selectedItem);
        }
        GridB.Rebind();
    }
    

    通过使用e.Handled = true,它停止了操作,我现在可以在其中实现我自己的逻辑

    【讨论】:

      猜你喜欢
      • 2015-08-01
      • 2022-07-06
      • 1970-01-01
      • 1970-01-01
      • 2017-09-15
      • 2014-06-16
      相关资源
      最近更新 更多