icsharpcode / WpfDesigner

The WPF Designer from SharpDevelop
MIT License
949 stars 251 forks source link

DragAndDrop support for DataFormats.FileDrop in designer? #58

Closed JoshWobbles closed 5 years ago

JoshWobbles commented 5 years ago

From what I can tell there is already a bunch of support in place for drag and drop functionality. I would like to expand on this for the purpose of being able to drag a file, such as a jpg, onto the design surface and have it create an Image element with the source set to my dragged file.

Due to protection levels of a couple sealed classes I am unable to just "overrule" the current drag-drop functionality, so how would I go about this?

jogibear9988 commented 5 years ago

not sure whats the best way, and I‘ve no time atm. best would be if you implement it diretc in wpf designer sourcecode, and when it works we look what changes we need in the original classes

JoshWobbles commented 5 years ago

What type is the native dragdrop functionality expecting? Perhaps I can simply reset the data property on drag enter.

JoshWobbles commented 5 years ago

Or, how to I create an element in the design panel from code behind?

                object newInstance = designSurface.DesignContext.Services.ExtensionManager.CreateInstanceWithCustomInstanceFactory(typeof(Image), null);
                DesignItem item = designSurface.DesignContext.Services.Component.RegisterComponentForDesigner(newInstance);
                designSurface.DesignContext.RootItem.ContentProperty.CollectionElements.Add(item);

This seems to work, but I am not sure it is the preferred method of doing so.

jogibear9988 commented 5 years ago

Or, how to I create an element in the design panel from code behind?

                object newInstance = designSurface.DesignContext.Services.ExtensionManager.CreateInstanceWithCustomInstanceFactory(typeof(Image), null);
                DesignItem item = designSurface.DesignContext.Services.Component.RegisterComponentForDesigner(newInstance);
                designSurface.DesignContext.RootItem.ContentProperty.CollectionElements.Add(item);

This seems to work, but I am not sure it is the preferred method of doing so.

I would change the first line to

 var newInstance = new Image()

The rest is fine.

But I also would open a new ChangeGroup before

 var cg = designSurface.DesignContext.RootElement.OpenGroup("aa");

and commit the group when finished. so that undo is possible

jogibear9988 commented 5 years ago

does it work?

JoshWobbles commented 5 years ago

Not the best solution, I'd still like to hook into the inbuilt drop support so content can be dropped in containers and not just the root grid, but its much better than nothing.

jogibear9988 commented 5 years ago

I‘ll look

jogibear9988 commented 5 years ago

can you look at my last commit?

JoshWobbles commented 5 years ago

Ill take a look, thanks! Any ides on this one; https://github.com/icsharpcode/WpfDesigner/issues/57 ? I haven't had much luck working around it on my end yet

jogibear9988 commented 5 years ago

no, I could not reproduce it.

couldn't you create a simple sample app? I tried in xamldesigner sample with mediaelement and autoplay, it works

JoshWobbles commented 5 years ago

would compiled app and pdb's be enough? Also, keep in mind, the issue does not present until the xaml is serialized then deserialized back into the designer, leading me to believe that the issue could be in the way xaml is parsed in.

jogibear9988 commented 5 years ago

try to add a MediaElement to the Demo.XamlDesigner App. Then switch to xaml code and back to design. It works

jogibear9988 commented 5 years ago

Don't know if I could help you when you give me the compiled app + pdb's

JoshWobbles commented 5 years ago

Unfortunately it doesn't work, I still get the error when a video is loaded in it, using the demo here or creating a new bare bone app all result in the same error. I posted back in the original issue my code and the XAML i am trying to load, try pointing the source to a local video of yours and see if it loads. then

jogibear9988 commented 5 years ago

What about the DragDrop Helper? Is this usefull?

JoshWobbles commented 5 years ago

Still tinkering, I get some pretty odd and erratic behavior on margin and alignment properties and I cant seem to override them, I have a feeling that may all be tied to the move/resize etc controls that are baked into the designer, because they can behave oddly at times too.