Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p><strong>Problem</strong>: In my WPF version, I am setting the textbox's text to empty (as a test), which occurs, but afterwards the TreeViewItem's header text is being pasted which is not what I want.</p> </blockquote> <p>I think a parent UI element is handling (and therefore overriding) the <code>Drop</code> event so you're not getting the results you expect. As a matter of fact, when trying to recreate your issue, I couldn't even get my TextBox.Drop event to fire. However, using the TextBox's PreviewDrop event, I was able to get what (I think) is your expected result. Try this:</p> <pre><code> private void textBox1_PreviewDrop(object sender, DragEventArgs e) { TextBox tb = sender as TextBox; if (tb != null) { // If the DataObject contains string data, extract it. if (e.Data.GetDataPresent(DataFormats.StringFormat)) { string fileName = e.Data.GetData(DataFormats.StringFormat) as string; using (StreamReader s = File.OpenText(fileName)) { ((TextBox)sender).Text = s.ReadToEnd(); } } } e.Handled = true; //be sure to set this to true } </code></pre> <p>I think that code snippet should answer most of the questions you posed except for this one:</p> <blockquote> <p>Why is TreeViewItem node always null in the WPF version?</p> </blockquote> <p>The <code>DataObject</code> you are passing in the DragDrop event does not support passing a <code>TreeViewItem</code>. In your code (and mine) we specify that the data format will be <code>DataFormats.StringFormat</code> which cannot be cast to a <code>TreeViewItem</code>.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload