Hello i want to dynamicly add placeholder controls for drag and and drop
in xaml it would be like this:
<StackPanel Background="Transparent" Grid.Row="0" Grid.Column="0">
<ig:DragDropManager.DropTarget> <ig:DropTarget IsDropTarget="True" DropChannels="C,D" /> </ig:DragDropManager.DropTarget>
<ig:DragDropManager.DragSource> <ig:DragSource IsDraggable="True" DragChannels="D" DataObject="{Binding}"> <i:Interaction.Triggers> <i:EventTrigger EventName="DragEnd"> <my:InvokeDelegateCommandAction Command="{Binding CommandSwopField}" CommandParameter="{Binding RelativeSource={RelativeSource Self}, Path=InvokeParameter}" /> </i:EventTrigger>
</ig:DragSource> </ig:DragDropManager.DragSource>
</StackPanel>
i have managed to write the following:
var sp = new StackPanel(); ObservableCollection<string> channels = new ObservableCollection<string>(); channels.Add("C"); channels.Add("D"); DropTarget dropTarget = new DropTarget(); dropTarget.IsDropTarget = true; dropTarget.DropChannels = channels; dropTarget.IsDropTarget = true; DragDropManager.SetDropTarget(sp, dropTarget);
channels.Clear(); channels.Add("D"); DragSource dragSource = new DragSource(); dragSource.IsDraggable = true;
dragSource.DropChannels = channels;
DragDropManager.SetDragSource(sp, dragSource);
but how to i add the even triggers with binding to command and commandparameters?
Hello Fredrik,
Thank you for your post. I have been looking into it and I created a sample project for with the functionality you want. Basically I used InvokeCommandAction as EventTrigger instead of InvokeDelegateCommandAction. Please let me know if this helps you or you need further assistance on this matter.
Looking forward for your reply.
Hello i dont think you understand my question.
I cant us any xaml code, I need to add a stackpanel from code, since i need it to be added at runtime.
in this stackpanel i need to have dragsource and a droptarget. this must be added from code.
my problem is adding the event trigger such as "DRAG END". I need help to understand how i should add this programmatically with a command and DragMoveEventsArgs as command parameter
I have modified your sample, so now the StackPanel is added runtime. Basically I created it as a Resource of the Grid, because Interaction’s Triggers cannot be added in code.
Hope this helps you.
Hello, your sollution still dosnt help me.
i need to be able to pump out mutiple stackpanels, and they need to be generated, cut and paste method wont work.
basicly the reason i cannot mark them up in xaml is that i will have performance issues, thus i need to genreate them from code.
I have modified the sample further, so now you can use the StackPanel multiple times whithout removing it from the Grid's Resources. Basically I wrap it in a DataTemplate and call its LoadContent method. Pelase let me know if you need further assistnace on the matter.
Thank you, was just what i needed.
have a nice weekend =)
Thank you for your feedback. I am glad that you resolved your issue and I believe that other community members may benefit from this as well.
Thanks again.