[英]MVVM ListBox ItemSource Get Collection Name
我正在實現多個列表框的動態拖放,需要在運行時確定集合名稱。
我的意思是->執行OnDrop事件時,我必須將項目添加到已經存在的集合中(集合可以具有多個成員),或者替換已經存在的項目(在只能具有一個成員的集合中)。 我想做以下事情:
var collection = (sender as System.Windows.Controls.ListBox).ItemsSource as IList;
if (collection.GetName() == "col_AllData")
{
//allow more than one member
}
else
{
//allow only one member
}
我可以嘗試檢查typeof() ,但是所有項目源都是同一類型。
任何幫助,將不勝感激。
我設法通過創建一個新的Dependency屬性來做到這一點:
public static readonly DependencyProperty AllowMultipleMembersProperty =
DependencyProperty.RegisterAttached("AllowMultipleMembers", typeof(bool), typeof(IP_ListBoxDragDropBehavior_New), new PropertyMetadata(new PropertyChangedCallback(OnAllowMultipleMembersPropertyChanged)));
在OnDrop事件中,我檢查以下內容:
bool? bMoreMembers = this.AssociatedObject.GetValue(AllowMultipleMembersProperty) as bool?;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.