Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > Avalon

Vista - Drag events

 
 
Old 09-03-2006   #1 (permalink)
Jon Davis


 
 

Drag events

I have Petzold's new book on WPF and was trying the Notepad clone and
noticed it does not have drag-and-drop working. Not surprising, it's just a
code sample. But I went to go add it and neither the window nor the textbox
"saw" the DragOver event when I implemented event handlers.

Is this implemented?

Thanks,
Jon



My System SpecsSystem Spec
Old 09-04-2006   #2 (permalink)
=?Utf-8?B?VGhlUkhvZ3Vl?=


 
 

RE: Drag events

Don't forget the SDK. Digging through the content tree is a good way to find
general topics. If you want to really know what WPF can do, you will have to
dig through the SDK.

http://windowssdk.msdn.microsoft.com.../ms754130.aspx

Here is the Drag-Drop link - it's under WinFX Development-> WPF ->Data.

http://windowssdk.msdn.microsoft.com.../ms749074.aspx

There isn't any book, including Charles, that will be as comprehensive as
the SDK. For example, Drag-Drop can be easy or complex depending on what you
want to do with it, and the SDK covers a number of areas a book may not
cover. Of course, the SDK doesn't cover everything either...it never
does...there are always holes.

Also, Charles book is a 100 level type book for WPF basics. He doesn't
discuss 3D, Typography, XPS, MSbuild, ....the list goes on and on... he had
to stop writing as there were no trees left in his local area

One thing to remember about Drag\Drop is the use of Adorners are important
for Drawing other WPF content over the top for some extra fun. Here is a link:

http://blogs.msdn.com/marcelolr/arch...03/543301.aspx

The Micosoft folks are blogging, and that is a great resource for finding
solutions to problems...for example I found the link above by searching for
"WPF 'drag and drop' adorners".


"Jon Davis" wrote:

> I have Petzold's new book on WPF and was trying the Notepad clone and
> noticed it does not have drag-and-drop working. Not surprising, it's just a
> code sample. But I went to go add it and neither the window nor the textbox
> "saw" the DragOver event when I implemented event handlers.
>
> Is this implemented?
>
> Thanks,
> Jon
>
>
>

My System SpecsSystem Spec
Old 09-05-2006   #3 (permalink)
Jon Davis


 
 

Re: Drag events

Thanks. Actually I was only trying to find out if netfx v3 supported
drag/drop and if so why it wasn't working for me.

It turns out I forgot to set AllowDrop property to True. Even after fixing
that, the textbox did not raise the event.

The app config:

Window ("NotepadClone")
-> DockPanel ("Dock")
-> -> Menu ("menu")
-> -> TextBox ("txtbox")

When I added the following, I got a messagebox from the DockPanel and from
the Window, but only when dragging to the menu (and nowhere else).


public NotepadClone()
{
.. . .
txtbox.AllowDrop = true;
dock.AllowDrop = true;
this.AllowDrop = true;
dock.DragOver += new DragEventHandler(dock_DragOver);
this.DragOver += new DragEventHandler(NotepadClone_DragOver);
txtbox.DragOver += new DragEventHandler(txtbox_DragOver);
....
}

void dock_DragOver(object sender, DragEventArgs e)
{
MessageBox.Show("What a drag! From dock"); // executes
}

void NotepadClone_DragOver(object sender, DragEventArgs e)
{
MessageBox.Show("What a drag! From window"); // executes
}

void txtbox_DragOver(object sender, DragEventArgs e)
{
MessageBox.Show("What a drag! From txtbox"); // DOES NOT execute
}


Thanks,
Jon


My System SpecsSystem Spec
Old 09-06-2006   #4 (permalink)
=?Utf-8?B?VGhlUkhvZ3Vl?=


 
 

Re: Drag events

You should look at the sample called DropOpenTextFile. If you follow the
Drag\Drop links in the SDK, it will take you to a 72meg sample beta2
drop...look in the "Editing" folder for the sample. The answer you are
looking for is in there...you are missing some code.



"Jon Davis" wrote:

> Thanks. Actually I was only trying to find out if netfx v3 supported
> drag/drop and if so why it wasn't working for me.
>
> It turns out I forgot to set AllowDrop property to True. Even after fixing
> that, the textbox did not raise the event.
>
> The app config:
>
> Window ("NotepadClone")
> -> DockPanel ("Dock")
> -> -> Menu ("menu")
> -> -> TextBox ("txtbox")
>
> When I added the following, I got a messagebox from the DockPanel and from
> the Window, but only when dragging to the menu (and nowhere else).
>
>
> public NotepadClone()
> {
> .. . .
> txtbox.AllowDrop = true;
> dock.AllowDrop = true;
> this.AllowDrop = true;
> dock.DragOver += new DragEventHandler(dock_DragOver);
> this.DragOver += new DragEventHandler(NotepadClone_DragOver);
> txtbox.DragOver += new DragEventHandler(txtbox_DragOver);
> ....
> }
>
> void dock_DragOver(object sender, DragEventArgs e)
> {
> MessageBox.Show("What a drag! From dock"); // executes
> }
>
> void NotepadClone_DragOver(object sender, DragEventArgs e)
> {
> MessageBox.Show("What a drag! From window"); // executes
> }
>
> void txtbox_DragOver(object sender, DragEventArgs e)
> {
> MessageBox.Show("What a drag! From txtbox"); // DOES NOT execute
> }
>
>
> Thanks,
> Jon
>
>
>

My System SpecsSystem Spec
Old 09-06-2006   #5 (permalink)
Jon Davis


 
 

Re: Drag events

That's real helpful. :-/

Look, I'm not going to download a 72 MB sample to get a very trivial
question answered. This is not important enough to me, unless you have an
explanation I am going to just assume then that this is either broken or
inconsistently designed. I'll wait around for a few more years for v2.

Cheers,
Jon


"TheRHogue" <TheRHogue@discussions.microsoft.com> wrote in message
news:6AC8CB23-8E23-40F6-9A24-4AD74CD570BF@microsoft.com...
> You should look at the sample called DropOpenTextFile. If you follow the
> Drag\Drop links in the SDK, it will take you to a 72meg sample beta2
> drop...look in the "Editing" folder for the sample. The answer you are
> looking for is in there...you are missing some code.
>
>
>
> "Jon Davis" wrote:
>
>> Thanks. Actually I was only trying to find out if netfx v3 supported
>> drag/drop and if so why it wasn't working for me.
>>
>> It turns out I forgot to set AllowDrop property to True. Even after
>> fixing
>> that, the textbox did not raise the event.
>>
>> The app config:
>>
>> Window ("NotepadClone")
>> -> DockPanel ("Dock")
>> -> -> Menu ("menu")
>> -> -> TextBox ("txtbox")
>>
>> When I added the following, I got a messagebox from the DockPanel and
>> from
>> the Window, but only when dragging to the menu (and nowhere else).
>>
>>
>> public NotepadClone()
>> {
>> .. . .
>> txtbox.AllowDrop = true;
>> dock.AllowDrop = true;
>> this.AllowDrop = true;
>> dock.DragOver += new DragEventHandler(dock_DragOver);
>> this.DragOver += new DragEventHandler(NotepadClone_DragOver);
>> txtbox.DragOver += new DragEventHandler(txtbox_DragOver);
>> ....
>> }
>>
>> void dock_DragOver(object sender, DragEventArgs e)
>> {
>> MessageBox.Show("What a drag! From dock"); // executes
>> }
>>
>> void NotepadClone_DragOver(object sender, DragEventArgs e)
>> {
>> MessageBox.Show("What a drag! From window"); // executes
>> }
>>
>> void txtbox_DragOver(object sender, DragEventArgs e)
>> {
>> MessageBox.Show("What a drag! From txtbox"); // DOES NOT execute
>> }
>>
>>
>> Thanks,
>> Jon
>>
>>
>>



My System SpecsSystem Spec
Old 09-06-2006   #6 (permalink)
Jon Davis


 
 

Re: Drag events

By the way, rule of thumb, a component should never expose an event if the
event is never raised. Textbox exposes DragOver but does not raise it even
with AllowDrop set to true. Hence, it is broken or flawed in its design. I'd
settle for broken but I have a doubt this will be fixed (we're already at
RC1), making it "by design" flawed.

Jon

"Jon Davis" <jon@REMOVE.ME.PLEASE.jondavis.net> wrote in message
news:%23JpP2Hf0GHA.4312@TK2MSFTNGP02.phx.gbl...
> That's real helpful. :-/
>
> Look, I'm not going to download a 72 MB sample to get a very trivial
> question answered. This is not important enough to me, unless you have an
> explanation I am going to just assume then that this is either broken or
> inconsistently designed. I'll wait around for a few more years for v2.
>
> Cheers,
> Jon
>
>
> "TheRHogue" <TheRHogue@discussions.microsoft.com> wrote in message
> news:6AC8CB23-8E23-40F6-9A24-4AD74CD570BF@microsoft.com...
>> You should look at the sample called DropOpenTextFile. If you follow the
>> Drag\Drop links in the SDK, it will take you to a 72meg sample beta2
>> drop...look in the "Editing" folder for the sample. The answer you are
>> looking for is in there...you are missing some code.
>>
>>
>>
>> "Jon Davis" wrote:
>>
>>> Thanks. Actually I was only trying to find out if netfx v3 supported
>>> drag/drop and if so why it wasn't working for me.
>>>
>>> It turns out I forgot to set AllowDrop property to True. Even after
>>> fixing
>>> that, the textbox did not raise the event.
>>>
>>> The app config:
>>>
>>> Window ("NotepadClone")
>>> -> DockPanel ("Dock")
>>> -> -> Menu ("menu")
>>> -> -> TextBox ("txtbox")
>>>
>>> When I added the following, I got a messagebox from the DockPanel and
>>> from
>>> the Window, but only when dragging to the menu (and nowhere else).
>>>
>>>
>>> public NotepadClone()
>>> {
>>> .. . .
>>> txtbox.AllowDrop = true;
>>> dock.AllowDrop = true;
>>> this.AllowDrop = true;
>>> dock.DragOver += new DragEventHandler(dock_DragOver);
>>> this.DragOver += new DragEventHandler(NotepadClone_DragOver);
>>> txtbox.DragOver += new DragEventHandler(txtbox_DragOver);
>>> ....
>>> }
>>>
>>> void dock_DragOver(object sender, DragEventArgs e)
>>> {
>>> MessageBox.Show("What a drag! From dock"); // executes
>>> }
>>>
>>> void NotepadClone_DragOver(object sender, DragEventArgs e)
>>> {
>>> MessageBox.Show("What a drag! From window"); // executes
>>> }
>>>
>>> void txtbox_DragOver(object sender, DragEventArgs e)
>>> {
>>> MessageBox.Show("What a drag! From txtbox"); // DOES NOT execute
>>> }
>>>
>>>
>>> Thanks,
>>> Jon
>>>
>>>
>>>

>
>



My System SpecsSystem Spec
Old 09-08-2006   #7 (permalink)
Jon Davis


 
 

Re: Drag events

Resolved on my own. It seems that although DragOver does not fire,
PreviewDragOver does fire. I'm sure there will be an explanation somewhere
(SDK or otherwise) on the whole idea of this "Preview-" prefix and what
PreviewDragOver suggests differently from DragOver.

TheRHogue, I apologize for my nasty reply. However, I did find the sample
you described and it did not help because event binding was implemented in
XAML whereas Petzold's NotepadClone does not use XAML at all.

Jon


"Jon Davis" <jon@REMOVE.ME.PLEASE.jondavis.net> wrote in message
news:uEEqhkV0GHA.4252@TK2MSFTNGP03.phx.gbl...
> Thanks. Actually I was only trying to find out if netfx v3 supported
> drag/drop and if so why it wasn't working for me.
>
> It turns out I forgot to set AllowDrop property to True. Even after fixing
> that, the textbox did not raise the event.
>
> The app config:
>
> Window ("NotepadClone")
> -> DockPanel ("Dock")
> -> -> Menu ("menu")
> -> -> TextBox ("txtbox")
>
> When I added the following, I got a messagebox from the DockPanel and from
> the Window, but only when dragging to the menu (and nowhere else).
>
>
> public NotepadClone()
> {
> . . .
> txtbox.AllowDrop = true;
> dock.AllowDrop = true;
> this.AllowDrop = true;
> dock.DragOver += new DragEventHandler(dock_DragOver);
> this.DragOver += new DragEventHandler(NotepadClone_DragOver);
> txtbox.DragOver += new DragEventHandler(txtbox_DragOver);
> ...
> }
>
> void dock_DragOver(object sender, DragEventArgs e)
> {
> MessageBox.Show("What a drag! From dock"); // executes
> }
>
> void NotepadClone_DragOver(object sender, DragEventArgs e)
> {
> MessageBox.Show("What a drag! From window"); // executes
> }
>
> void txtbox_DragOver(object sender, DragEventArgs e)
> {
> MessageBox.Show("What a drag! From txtbox"); // DOES NOT execute
> }
>
>
> Thanks,
> Jon
>



My System SpecsSystem Spec
Old 09-08-2006   #8 (permalink)
Jon Davis


 
 

Re: Drag events


> TheRHogue, I apologize for my nasty reply. However, I did find the sample
> you described and it did not help because event binding was implemented in
> XAML whereas Petzold's NotepadClone does not use XAML at all.


... but it did point out the "Preview-" nomenclature, which led to my own
findings. To that extent, it was indeed helpful. Thanks.

Jon


My System SpecsSystem Spec
 

Thread Tools


Similar Threads
Thread Forum
Events PowerShell
Access denied trying to "md"? Drag & Drop is now drag, drop, OK, OK ???? Vista installation & setup
Events, events PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46