0

我的目标是创建一个带有可移动节点的树视图。所以,我在以下链接中找到了灵感:[Treeview with drag and drop] https://www.codeproject.com/Articles/55168/Drag-and-Drop-Feature-in-WPF-TreeView-Control

我的问题是:如何在 viewmodel 这个事件中绑定命令?

<treeview.itemcontainerstyle>

    <style targettype="{x:Type TreeViewItem}">        
      <EventSetter Event="TreeViewItem.DragOver"  Handler="treeView_DragOver"/>
      <EventSetter Event="TreeViewItem.Drop" Handler="treeView_Drop"/>
      <EventSetter Event="TreeViewItem.MouseMove" Handler="treeView_MouseMove"/> 
      <EventSetter Event="TreeViewItem.MouseDown" Handler="treeView_MouseDown"/>
    </style>              

 </treeview.itemcontainerstyle> 

我试试这个:

<EventSetter Event="TreeViewItem.DragOver"  Handler="{Binding DragOverCommand}"/>

并在相对视图模型中创建 DragOverCommand:

ICommand _cmdDragOverCommand;
        public ICommand DragOverCommand
        {
            get
            {
                if (_cmdDragOverCommand== null)
                {
                    _cmdDragOverCommand= new RelayCommand<tvMenuItem>(DragOverCommandExecute, CanDragOverCommandExecute);
                }
                return _cmdDragOverCommand;
            }
        }

        private bool CanDragOverCommandExecute(object param)
        {
            return true;
        }

        private void DragOverCommandExecute(object param)
        {
            try
            {
               ...     
            }
            catch (Exception ex)
            {
                ...
            }
        }

但在运行时显示以下错误: 在此处输入图像描述

你有想法吗?

有免费的图形控件吗?

提前致谢

干杯

4

0 回答 0