WPF C#Custom UserControl如何添加接受绑定的属性

时间:2011-01-19 21:07:26

标签: c# wpf wpf-controls custom-controls dependency-properties

我正在尝试设计一个由TextEditor和PopUp组成的CustomUserControl ......

因此Popup控件应绑定到列表... 我称之为BindingList。此属性应接受任何类型,如ObservableCollection,List,Ienumerable,例如(集合)......

<my:CustomControl BindingList="{Binding Path=Collection}"


 public IEnumerable<object> BindingList
    {
        get { return (IEnumerable<object>)GetValue(BindingListProp); }
        set { SetValue(BindingListProp, value); }
    }

BindinglistProp

 public static readonly DependencyProperty BindingListProp = DependencyProperty.Register(??????

我不知道它应该如何接受绑定。

我该如何处理传递的Collection?当它是一种我不知道的类型

    class Person
    {
        private string _Name;
        private string _forename;


        public string Name
        {
            get { return _Name; }
            set
            {
                _Name = value;
            }
        }

        public string Forename
        {
            get { return _forename; }
            set
            {
                _forename = value;
            }
        }
    }

感谢您提供任何提示,教程或代码段。

真诚 标记

2 个答案:

答案 0 :(得分:3)

public IObservable<object> BindingList
{
  get { return (IObservable<object>)base.GetValue(BindingListProperty); }
  set { base.SetValue(BindingListProperty, value); }
}

public static DependencyProperty BindingListProperty =
  DependencyProperty.Register(
  "BindingList",
  typeof(IObservable<object>),
  typeof(CustomControl),
  new PropertyMetadata(null));

答案 1 :(得分:1)

CollectionViewSource.GetDefaultView以常见方式处理任何集合。