[英]Creating xaml element in code-behind using gong dragdrop
我是C#的新手。 這可能是一個相當簡單的問題,但我找不到任何有關此的示例。 我只是想知道在代碼隱藏文件( .xaml.cs
)中創建XAML元素時,是否可以使用其他開放源代碼庫(例如GongSolutions.WPF.DragDrop
)屬性?
下面是一個示例,我可以在code-behind( .xaml.cs
)文件中創建以下XAML代碼嗎?
<...
xmlns:dd="urn:gong-wpf-dragdrop"
...
>
...
<ListBox ItemsSource="{Binding Collection}"
dd:DragDrop.IsDragSource="True"
dd:DragDrop.IsDropTarget="True" />
謝謝你的幫助!!!
您通常需要從后面的代碼中知道如何為AttachedProperties設置值。 下面的代碼應該對您的情況有所幫助,
listBox.SetValue(GongSolutions.Wpf.DragDrop.DragDrop.IsDragSourceProperty, true);
listBox.SetValue(GongSolutions.Wpf.DragDrop.DragDrop.IsDropTargetProperty, true);
如果您想確保輸入安全,可以這樣設置,
GongSolutions.Wpf.DragDrop.DragDrop.SetIsDragSource(listBox, true);
GongSolutions.Wpf.DragDrop.DragDrop.SetIsDropTarget(listBox, true);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.