简体   繁体   English

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

[英]WPF C# Custom UserControl How To add a Property which accepts an Binding

I'm trying to design a CustomUserControl which consits of an TextEditor and a PopUp... 我正在尝试设计一个CustomUserControl,它由TextEditor和PopUp构成......

So the Popup control should be binded to a list... I called it BindingList. 因此Popup控件应绑定到列表...我称之为BindingList。 This Property should accept any types like ObservableCollection, List, Ienumerable for example(Collections)... 此属性应接受任何类型,如ObservableCollection,List,Ienumerable,例如(集合)...

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


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

The BindinglistProp BindinglistProp

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

I have no clue how it should look like that it can accept a binding. 我不知道它应该如何接受绑定。

And how should i deal with the Collection which is passed? 我应该如何处理传递的Collection? when it is of a type which i don`t know 当它是一种我不知道的类型

like 喜欢

    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;
            }
        }
    }

Thanks for any hints, tutorials or code snippets. 感谢任何提示,教程或代码片段。

sincerely Mark 马克

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));

查看CollectionViewSource.GetDefaultView以常用方式处理任何集合。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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