This project is read-only.

Drag Drop on Inner Elements?

Jun 20, 2008 at 12:39 AM
Hi Pavan,

I'm probably doing something stupid but I'm trying to get the Drag/Drop properties to work in my window but I can't seem to figure it out.
I've got a window like this:

<stackpanel>
    <mycustomControl:SomeControl />
    <mycustomControl:SomeControl />
</stackpanel>
each custom control has a TreeView and I want to be able to drag/drop TreeViewItems from one to the other, however when I attach the source property to one control and the target property to the other CustomControl, the IsDraggable method in DefaultDragSourceAdvisor shows the UIElement as type mycustomControl instead of the TreeViewItem being displayed on the control.  Am I using the attached properties wrong?  What do you recommend?

Thanks!!!

Roland
http://WPFBlog.info
Jun 20, 2008 at 1:02 AM
Can you attach the advisors to the TreeViews directly ? That could possibly give you the right elements. Let me know.
Jun 20, 2008 at 1:50 PM


pavanpodila wrote:
Can you attach the advisors to the TreeViews directly ? That could possibly give you the right elements. Let me know.



I also have a problem with inner elements. The error I keep getting is similar to this:

System.Windows.Markup.XamlParseException occurred
  Message="Cannot convert the value in attribute 'DragSourceAdvisor' to object of type 'FluidKit.Helpers.DragDrop.IDragSourceAdvisor'. Value cannot be null.\r\nParameter name: name  Error at object 'ItemContainer' in markup file 'TargetGroupConfiguratorSpike;component/controls/targetconfigurationbasecontrol.xaml' Line 51 Position 87."
  Source="PresentationFramework"
  LineNumber=51
  LinePosition=87
  NameContext="ItemContainer"
  StackTrace:
       at System.Windows.Markup.XamlParseException.ThrowException(String message, Exception innerException, Int32 lineNumber, Int32 linePosition, Uri baseUri, XamlObjectIds currentXamlObjectIds, XamlObjectIds contextXamlObjectIds, Type objectType)
       at System.Windows.Markup.XamlParseException.ThrowException(ParserContext parserContext, Int32 lineNumber, Int32 linePosition, String message, Exception innerException)
       at System.Windows.Markup.BamlRecordReader.ThrowExceptionWithLine(String message, Exception innerException)
       at System.Windows.Markup.BamlRecordReader.BaseReadOptimizedMarkupExtension(Object element, Int16 attributeId, PropertyDefinition propertyDefinition, Object value)
       at System.Windows.Markup.BamlRecordReader.ReadPropertyWithExtensionRecord(BamlPropertyWithExtensionRecord bamlPropertyRecord)
       at System.Windows.Markup.BamlRecordReader.ReadRecord(BamlRecord bamlRecord)
       at System.Windows.Markup.BamlRecordReader.Read(Boolean singleRecord)
       at System.Windows.Markup.TreeBuilderBamlTranslator.ParseFragment()
       at System.Windows.Markup.TreeBuilder.Parse()
       at System.Windows.Markup.XamlReader.LoadBaml(Stream stream, ParserContext parserContext, Object parent, Boolean closeStream)
       at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
       at TargetGroupConfiguratorSpike.TargetConfigurationBaseControl.InitializeComponent() in c:\Morten\Spikes\TargetGroupConfiguratorSpike\TargetGroupConfiguratorSpike\Controls\TargetConfigurationBaseControl.xaml:line 1
       at TargetGroupConfiguratorSpike.TargetConfigurationBaseControl..ctor() in C:\Morten\Spikes\TargetGroupConfiguratorSpike\TargetGroupConfiguratorSpike\Controls\TargetConfigurationBaseControl.xaml.cs:line 23
  InnerException: System.ArgumentNullException
       Message="Value cannot be null.\r\nParameter name: name"
       Source="mscorlib"
       ParamName="name"
       StackTrace:
            at System.Resources.ResourceManager.GetString(String name, CultureInfo culture)
            at System.Resources.ResourceManager.GetString(String name)
            at System.Windows.SR.Get(String id, Object[] args)
            at System.Windows.Markup.BamlRecordReader.ThrowException(String id, String parameter)
            at System.Windows.Markup.BamlRecordReader.ThrowException(String id, String parameter)
            at System.Windows.StaticResourceExtension.ProvideValueInternal(IBamlReader bamlReader, Object targetObject, Object targetProperty, Boolean allowDeferredReference)
            at System.Windows.StaticResourceExtension.ProvideValue(IServiceProvider serviceProvider)
            at System.Windows.Markup.BamlRecordReader.ProvideValueFromMarkupExtension(MarkupExtension markupExtension, Object obj, Object member)
            at System.Windows.Markup.BamlRecordReader.BaseReadOptimizedMarkupExtension(Object element, Int16 attributeId, PropertyDefinition propertyDefinition, Object value)
       InnerException:

Here I have used a very slightly modified version of the DefaultDragSource/DropTargetAdvisor classes, and assigned them to a wrap panel inside my usercontrol. I then have two of them on a window and was hoping to drag a user control from one of my controls into another.

Any hints to point me in the right direction is appreciated.


Thanks,

Morten
Jun 21, 2008 at 2:07 AM
Morten,
       From the stack trace it looks like the XamlParser is having trouble casting your instance of the DragSourceAdvisor to IDragSourceAdvisor. Could there be some interface mismatch ?
Jun 21, 2008 at 6:16 AM


pavanpodila wrote:
Morten,
       From the stack trace it looks like the XamlParser is having trouble casting your instance of the DragSourceAdvisor to IDragSourceAdvisor. Could there be some interface mismatch ?



I don't think so. I have just referenced the FluidKit dll and copied the two default advisors from the dragdroppanel showcase. I did modify a couple of things, but neither of those changed any interface contract things.

Would you be willing to have a look at my project to see if there is something very obvious I am doing wrong?


Morten
Jun 21, 2008 at 1:34 PM
Morten,
    You can send me the files to my email (found on home page). I'll take a look.