Click here to Skip to main content
15,913,941 members
Home / Discussions / WPF
   

WPF

 
AnswerRe: Google annoucment Pin
vivasaayi28-Sep-09 1:08
vivasaayi28-Sep-09 1:08 
GeneralRe: Google annoucment Pin
Ian Shlasko28-Sep-09 3:03
Ian Shlasko28-Sep-09 3:03 
QuestionNeed to access control in another page Pin
CBenac25-Sep-09 18:26
CBenac25-Sep-09 18:26 
AnswerRe: Need to access control in another page Pin
Mark Salsbery28-Sep-09 6:44
Mark Salsbery28-Sep-09 6:44 
GeneralRe: Need to access control in another page Pin
CBenac28-Sep-09 10:56
CBenac28-Sep-09 10:56 
GeneralRe: Need to access control in another page Pin
Mark Salsbery28-Sep-09 13:40
Mark Salsbery28-Sep-09 13:40 
QuestionWhy doesn't the AllowDrop property work with a TextBox? [modified] Pin
fjparisIII25-Sep-09 5:18
fjparisIII25-Sep-09 5:18 
AnswerRe: Why doesn't the AllowDrop property work with a TextBox? Pin
Pete O'Hanlon25-Sep-09 10:24
mvePete O'Hanlon25-Sep-09 10:24 
As you have found, the TextBox (as well as RichTextBox and FlowDocument) marks drag and drop events as handled, which causes you real problems in cases like this. At first, you might think that this leaves you with a problem, but rejoice - WPF provides you with all that you need to do what you want.

The first thing that you need to do is modify the textbox to use certain preview events (PreviewDragEnter, PreviewDragOver and PreviewDragDrop) like so:
<TextBox
    AllowDrop="True"
    PreviewDragEnter="TextBox_PreviewDragOver" <-- Notice how this event
    PreviewDragOver="TextBox_PreviewDragOver"  <-- and this one map to the same event handler.
    PreviewDrop="TextBox_PreviewDrop"/>
Then, all you need to do is add the code for the events in the code behind:
private void TextBox_PreviewDragOver(object sender, DragEventArgs e)
{
    e.Effects = DragDropEffects.All;
    e.Handled = true;
}

private void TextBox_PreviewDrop(object sender, DragEventArgs e)
{
    object text = e.Data.GetData(DataFormats.FileDrop);
    TextBox tb = sender as TextBox;
    if (tb != null)
    {
        tb.Text = string.Format("{0}",((string[])text)[0]);
    }
}
This sample simply picks the filename out and writes it to the textbox - you can do it with whatever you want. There, I hope that helps.

"WPF has many lovers. It's a veritable porn star!" - Josh Smith

As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.


My blog | My articles | MoXAML PowerToys | Onyx



GeneralRe: Why doesn't the AllowDrop property work with a TextBox? [modified] Pin
fjparisIII26-Sep-09 4:48
fjparisIII26-Sep-09 4:48 
GeneralRe: Why doesn't the AllowDrop property work with a TextBox? Pin
Pete O'Hanlon27-Sep-09 23:34
mvePete O'Hanlon27-Sep-09 23:34 
GeneralRe: Why doesn't the AllowDrop property work with a TextBox? Pin
fjparisIII28-Sep-09 5:50
fjparisIII28-Sep-09 5:50 
GeneralRe: Why doesn't the AllowDrop property work with a TextBox? Pin
Pete O'Hanlon28-Sep-09 8:50
mvePete O'Hanlon28-Sep-09 8:50 
GeneralRe: Why doesn't the AllowDrop property work with a TextBox? Pin
fjparisIII28-Sep-09 16:41
fjparisIII28-Sep-09 16:41 
QuestionCan't update GUI with textbox Text Pin
marca29224-Sep-09 20:14
marca29224-Sep-09 20:14 
QuestionNeed to accept drop from drag and drop operation from Windows Explorer Pin
fjparisIII24-Sep-09 16:08
fjparisIII24-Sep-09 16:08 
AnswerRe: Need to accept drop from drag and drop operation from Windows Explorer Pin
Gideon Engelberth25-Sep-09 3:22
Gideon Engelberth25-Sep-09 3:22 
GeneralRe: Need to accept drop from drag and drop operation from Windows Explorer Pin
fjparisIII25-Sep-09 4:06
fjparisIII25-Sep-09 4:06 
QuestionFont difference between XP and Vista in wpf app Pin
ausadmin24-Sep-09 13:47
ausadmin24-Sep-09 13:47 
AnswerRe: Font difference between XP and Vista in wpf app Pin
Christian Graus24-Sep-09 14:22
protectorChristian Graus24-Sep-09 14:22 
QuestionCustom control Pin
Mikey_H23-Sep-09 9:11
Mikey_H23-Sep-09 9:11 
AnswerRe: Custom control Pin
Richard MacCutchan23-Sep-09 12:27
mveRichard MacCutchan23-Sep-09 12:27 
GeneralRe: Custom control Pin
Mikey_H25-Sep-09 3:19
Mikey_H25-Sep-09 3:19 
GeneralRe: Custom control Pin
Richard MacCutchan25-Sep-09 7:55
mveRichard MacCutchan25-Sep-09 7:55 
QuestionCant see columns in listview on designer Pin
Haim Nachum23-Sep-09 4:36
Haim Nachum23-Sep-09 4:36 
AnswerRe: Cant see columns in listview on designer Pin
ABitSmart23-Sep-09 14:25
ABitSmart23-Sep-09 14:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.