简体   繁体   中英

Creating xaml element in code-behind using gong dragdrop

I am fairly new to C#. This may be a fairly straight forward question, but I couldn't find any example about this. I am just wondering if there is any way when I create XAML element in the code-behind file( .xaml.cs ), I can use other open source library(such as GongSolutions.WPF.DragDrop ) property in the element?

An example will be as following, can I create the following XAML code in the code-behind( .xaml.cs ) file?

<...
xmlns:dd="urn:gong-wpf-dragdrop"
...
>
...
<ListBox ItemsSource="{Binding Collection}"
         dd:DragDrop.IsDragSource="True"
         dd:DragDrop.IsDropTarget="True" />

Thanks for your help!!!

You generally need to know how to set values for AttachedProperties from code behind. Below code should help for your case,

listBox.SetValue(GongSolutions.Wpf.DragDrop.DragDrop.IsDragSourceProperty, true);
listBox.SetValue(GongSolutions.Wpf.DragDrop.DragDrop.IsDropTargetProperty, true);

If you want to be type safe, you can set the same like this,

GongSolutions.Wpf.DragDrop.DragDrop.SetIsDragSource(listBox, true);
GongSolutions.Wpf.DragDrop.DragDrop.SetIsDropTarget(listBox, true);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM