【问题标题】:MVVM ListBox ItemSource Get Collection NameMVVM ListBox ItemSource 获取集合名称
【发布时间】:2015-01-15 13:56:17
【问题描述】:

我正在多个列表框上实现动态拖放,我需要在运行时找出集合名称。

我的意思 -> 在执行 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(),但是所有项目来源都属于同一类型。

任何帮助将不胜感激。

【问题讨论】:

    标签: c# wpf mvvm listbox


    【解决方案1】:

    我设法通过创建一个新的 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?;
    

    【讨论】:

      猜你喜欢
      • 2012-06-14
      • 2013-08-29
      • 1970-01-01
      • 2018-02-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-19
      相关资源
      最近更新 更多