C# 碱性溶液样品无滴
我试图在一个简单的WPF MVVM Light示例中实现gongsolutions中的拖放功能,但是我无法让它工作。我可以拖动项目(它进入事件),但不能拖放它们。我得到了不可用的鼠标图标,而不是能够放下它 这是xaml:C# 碱性溶液样品无滴,c#,wpf,drag-and-drop,mvvm-light,C#,Wpf,Drag And Drop,Mvvm Light,我试图在一个简单的WPF MVVM Light示例中实现gongsolutions中的拖放功能,但是我无法让它工作。我可以拖动项目(它进入事件),但不能拖放它们。我得到了不可用的鼠标图标,而不是能够放下它 这是xaml: xmlns:dd="clr-namespace:GongSolutions.Wpf.DragDrop;assembly=GongSolutions.Wpf.DragDrop" <StackPanel Orientation = "Horizon
xmlns:dd="clr-namespace:GongSolutions.Wpf.DragDrop;assembly=GongSolutions.Wpf.DragDrop"
<StackPanel Orientation = "Horizontal" >
<ListView Width="200" DisplayMemberPath="Name" ItemsSource="{Binding Customers}"
dd:DragDrop.IsDragSource="True" AllowDrop="True" dd:DragDrop.IsDropTarget="True" dd:DragDrop.DropHandler="{Binding}" />
<ListView Width="200" DisplayMemberPath="EmployeeName" ItemsSource="{Binding Employees}"
dd:DragDrop.IsDragSource="True" AllowDrop="True" dd:DragDrop.IsDropTarget="True" dd:DragDrop.DropHandler="{Binding}"/>
</StackPanel>
xmlns:dd=“clr命名空间:GongSolutions.Wpf.DragDrop;assembly=GongSolutions.Wpf.DragDrop”
这是我的viewmodel:
public class MainViewModel : ViewModelBase, IDropTarget
{
private ObservableCollection<Model.Customer> _Customers;
public ObservableCollection<Model.Customer> Customers
{
get
{
return _Customers;
}
set
{
_Customers = value;
RaisePropertyChanged("Customers");
}
}
private ObservableCollection<Model.Employee> _Employees;
public ObservableCollection<Model.Employee> Employees
{
get
{
return _Employees;
}
set
{
_Employees = value;
RaisePropertyChanged("Employees");
}
}
public MainViewModel()
{
Customers = new ObservableCollection<Customer>();
Employees = new ObservableCollection<Employee>();
Customers.Add(new Model.Customer { Name = "Company A" });
Customers.Add(new Model.Customer { Name = "Company B" });
Employees.Add(new Model.Employee { EmployeeName = "Tom" });
Employees.Add(new Model.Employee { EmployeeName = "Jos" });
}
////public override void Cleanup()
////{
//// // Clean up if needed
//// base.Cleanup();
////}
public void DragOver(DropInfo dropInfo)
{
System.Diagnostics.Debug.WriteLine(dropInfo.Data.ToString());
}
public void Drop(DropInfo dropInfo)
{
}
}
public类MainViewModel:ViewModelBase,IDROPTTarget
{
私人可观测收集客户;
公开收集客户
{
得到
{
退回客户;
}
设置
{
_顾客=价值;
RaisePropertyChanged(“客户”);
}
}
私人可观察收集的员工;
公开收集雇员
{
得到
{
返回(u)员工;;
}
设置
{
_员工=价值;
RaiseProperty变更(“员工”);
}
}
公共主视图模型()
{
客户=新的可观察收集();
员工=新的可观察集合();
Customers.Add(newmodel.Customer{Name=“Company A”});
Customers.Add(newmodel.Customer{Name=“Company B”});
Add(新的Model.Employee{EmployeeName=“Tom”});
Add(新的Model.Employee{EmployeeName=“Jos”});
}
////公共覆盖无效清除()
////{
//////如果需要,请清理
////base.Cleanup();
////}
公共无效DragOver(DropInfo DropInfo)
{
System.Diagnostics.Debug.WriteLine(dropInfo.Data.ToString());
}
公共作废删除(DropInfo DropInfo)
{
}
}
示例项目:您的目标必须在DragOver处理程序中设置DragDropEffect以允许拖放:
public void DragOver(DropInfo dropInfo)
{
dropInfo.Effects = System.Windows.DragDropEffects.Move;
}
您是否尝试在DragOver处理程序中将dropInfo.Effects属性设置为DragDropEffects.Move(或其他内容)?正确!谢谢你的时间!