1. <tfoot id='E1VIs'></tfoot>
  2. <legend id='E1VIs'><style id='E1VIs'><dir id='E1VIs'><q id='E1VIs'></q></dir></style></legend>

      <bdo id='E1VIs'></bdo><ul id='E1VIs'></ul>

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

      在 wpf 中拖放路径

      时间:2023-08-25
          1. <small id='9SMMP'></small><noframes id='9SMMP'>

              <tbody id='9SMMP'></tbody>

                <bdo id='9SMMP'></bdo><ul id='9SMMP'></ul>
                <legend id='9SMMP'><style id='9SMMP'><dir id='9SMMP'><q id='9SMMP'></q></dir></style></legend>
              • <tfoot id='9SMMP'></tfoot>
                <i id='9SMMP'><tr id='9SMMP'><dt id='9SMMP'><q id='9SMMP'><span id='9SMMP'><b id='9SMMP'><form id='9SMMP'><ins id='9SMMP'></ins><ul id='9SMMP'></ul><sub id='9SMMP'></sub></form><legend id='9SMMP'></legend><bdo id='9SMMP'><pre id='9SMMP'><center id='9SMMP'></center></pre></bdo></b><th id='9SMMP'></th></span></q></dt></tr></i><div id='9SMMP'><tfoot id='9SMMP'></tfoot><dl id='9SMMP'><fieldset id='9SMMP'></fieldset></dl></div>
                本文介绍了在 wpf 中拖放路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                是否可以使用鼠标事件处理程序在 wpf 中拖放路径?特别是我想用鼠标左键拖动一条路径并将其鼠标放在网格上.如何做到这一点?

                Is it possible to drag and drop a path in a wpf using Mouse Eventhandlers? In partcular I want to drag a path with the left mouse button and to mouse it on the grid. How can this be done?

                推荐答案

                试试这个:

                鉴于:文本框名称为TextBox1"

                Given: TextBox name is "TextBox1"

                    public MainWindow()
                    {
                        // Initialize UI
                        InitializeComponent();
                
                        // Loaded event
                        this.Loaded += delegate
                            {
                                TextBox1.AllowDrop = true;
                                TextBox1.PreviewDragEnter += TextBox1PreviewDragEnter;
                                TextBox1.PreviewDragOver += TextBox1PreviewDragOver;
                                TextBox1.Drop += TextBox1DragDrop;
                            };
                    }
                
                    /// <summary>
                    /// We have to override this to allow drop functionality.
                    /// </summary>
                    /// <param name="sender"></param>
                    /// <param name="e"></param>
                    void TextBox1PreviewDragOver(object sender, DragEventArgs e)
                    {
                        e.Handled = true;
                    }
                
                    /// <summary>
                    /// Evaluates the Data and performs the DragDropEffect
                    /// </summary>
                    /// <param name="sender"></param>
                    /// <param name="e"></param>
                    private void TextBox1PreviewDragEnter(object sender, DragEventArgs e)
                    {
                        if (e.Data.GetDataPresent(DataFormats.FileDrop))
                        {
                            e.Effects = DragDropEffects.Copy;
                        }
                        else
                        {
                            e.Effects = DragDropEffects.None;
                        }
                    }
                
                    /// <summary>
                    /// The drop activity on the textbox.
                    /// </summary>
                    /// <param name="sender"></param>
                    /// <param name="e"></param>
                    private void TextBox1DragDrop(object sender, DragEventArgs e)
                    {
                        // Get data object
                        var dataObject = e.Data as DataObject;
                
                        // Check for file list
                        if (dataObject.ContainsFileDropList())
                        {
                            // Clear values
                            TextBox1.Text = string.Empty;
                
                            // Process file names
                            StringCollection fileNames = dataObject.GetFileDropList();
                            StringBuilder bd = new StringBuilder();
                            foreach (var fileName in fileNames)
                            {
                                bd.Append(fileName + "
                ");
                            }
                
                            // Set text
                            TextBox1.Text = bd.ToString();
                        }
                    }
                

                这篇关于在 wpf 中拖放路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:拖放在 C# 中不起作用 下一篇:用代码模拟窗口拖放?

                相关文章

                最新文章

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

                    <bdo id='zOJTz'></bdo><ul id='zOJTz'></ul>
                  1. <small id='zOJTz'></small><noframes id='zOJTz'>

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