1. <legend id='AI6To'><style id='AI6To'><dir id='AI6To'><q id='AI6To'></q></dir></style></legend><tfoot id='AI6To'></tfoot>
      • <bdo id='AI6To'></bdo><ul id='AI6To'></ul>
    2. <small id='AI6To'></small><noframes id='AI6To'>

      <i id='AI6To'><tr id='AI6To'><dt id='AI6To'><q id='AI6To'><span id='AI6To'><b id='AI6To'><form id='AI6To'><ins id='AI6To'></ins><ul id='AI6To'></ul><sub id='AI6To'></sub></form><legend id='AI6To'></legend><bdo id='AI6To'><pre id='AI6To'><center id='AI6To'></center></pre></bdo></b><th id='AI6To'></th></span></q></dt></tr></i><div id='AI6To'><tfoot id='AI6To'></tfoot><dl id='AI6To'><fieldset id='AI6To'></fieldset></dl></div>

      1. WPF 拖放 - 从 DragEventArgs 获取原始源信息

        时间:2023-08-25
        <i id='OZTvI'><tr id='OZTvI'><dt id='OZTvI'><q id='OZTvI'><span id='OZTvI'><b id='OZTvI'><form id='OZTvI'><ins id='OZTvI'></ins><ul id='OZTvI'></ul><sub id='OZTvI'></sub></form><legend id='OZTvI'></legend><bdo id='OZTvI'><pre id='OZTvI'><center id='OZTvI'></center></pre></bdo></b><th id='OZTvI'></th></span></q></dt></tr></i><div id='OZTvI'><tfoot id='OZTvI'></tfoot><dl id='OZTvI'><fieldset id='OZTvI'></fieldset></dl></div>

            • <legend id='OZTvI'><style id='OZTvI'><dir id='OZTvI'><q id='OZTvI'></q></dir></style></legend>
                <tbody id='OZTvI'></tbody>
              <tfoot id='OZTvI'></tfoot>
            • <small id='OZTvI'></small><noframes id='OZTvI'>

                <bdo id='OZTvI'></bdo><ul id='OZTvI'></ul>
                1. 本文介绍了WPF 拖放 - 从 DragEventArgs 获取原始源信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在尝试使用 MVVM 编写拖放功能,这将允许我将 PersonModel 对象从一个 ListView 拖到另一个.

                  I am trying write Drag and Drop functionality using MVVM which will allow me to drag PersonModel objects from one ListView to another.

                  这几乎可以工作,但我需要能够从 DragEventArgs 中获取源 ListView 的 ItemsSource,但我不知道该怎么做.

                  This is almost working but I need to be able to get the ItemsSource of the source ListView from the DragEventArgs which I cant figure out how to do.

                  private void OnHandleDrop(DragEventArgs e)
                  {
                      if (e.Data != null && e.Data.GetDataPresent("myFormat"))
                      {
                          var person = e.Data.GetData("myFormat") as PersonModel;
                          //Gets the ItemsSource of the source ListView
                          ..
                  
                          //Gets the ItemsSource of the target ListView and Adds the person to it
                          ((ObservableCollection<PersonModel>)(((ListView)e.Source).ItemsSource)).Add(person);
                      }
                  }
                  

                  任何帮助将不胜感激.

                  谢谢!

                  推荐答案

                  我在另一个问题中找到了答案

                  这样做的方法是将源ListView传递给DragDrow.DoDragDrop方法即.

                  The way to do it is to pass the source ListView into the DragDrow.DoDragDrop method ie.

                  在处理ListView的PreviewMouseMove的方法中做-

                  In the method which handles the PreviewMouseMove for the ListView do-

                  private static void List_MouseMove(MouseEventArgs e)
                  {
                      if (e.LeftButton == MouseButtonState.Pressed)
                      {
                          if (e.Source != null)
                          {
                              DragDrop.DoDragDrop((ListView)e.Source, (ListView)e.Source, DragDropEffects.Move);
                          }
                      }
                  }
                  

                  然后在 OnHandleDrop 方法中将代码改为

                  and then in the OnHandleDrop method change the code to

                  private static void OnHandleDrop(DragEventArgs e)
                  {
                      if (e.Data != null && e.Data.GetDataPresent("System.Windows.Controls.ListView"))
                      {
                          //var person = e.Data.GetData("myFormat") as PersonModel;
                          //Gets the ItemsSource of the source ListView and removes the person
                          var source = e.Data.GetData("System.Windows.Controls.ListView") as ListView;
                          if (source != null)
                          {
                              var person = source.SelectedItem as PersonModel;
                              ((ObservableCollection<PersonModel>)source.ItemsSource).Remove(person);
                  
                              //Gets the ItemsSource of the target ListView
                              ((ObservableCollection<PersonModel>)(((ListView)e.Source).ItemsSource)).Add(person);
                          }
                      }
                  }
                  

                  这篇关于WPF 拖放 - 从 DragEventArgs 获取原始源信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何在打开对话框时禁用拖放 下一篇:ListBox MultiSelect 拖放问题

                  相关文章

                  最新文章

                  <legend id='LqE2E'><style id='LqE2E'><dir id='LqE2E'><q id='LqE2E'></q></dir></style></legend>

                    <bdo id='LqE2E'></bdo><ul id='LqE2E'></ul>
                  <tfoot id='LqE2E'></tfoot>

                    1. <small id='LqE2E'></small><noframes id='LqE2E'>

                    2. <i id='LqE2E'><tr id='LqE2E'><dt id='LqE2E'><q id='LqE2E'><span id='LqE2E'><b id='LqE2E'><form id='LqE2E'><ins id='LqE2E'></ins><ul id='LqE2E'></ul><sub id='LqE2E'></sub></form><legend id='LqE2E'></legend><bdo id='LqE2E'><pre id='LqE2E'><center id='LqE2E'></center></pre></bdo></b><th id='LqE2E'></th></span></q></dt></tr></i><div id='LqE2E'><tfoot id='LqE2E'></tfoot><dl id='LqE2E'><fieldset id='LqE2E'></fieldset></dl></div>