所以,我试图执行一些数据绑定到我有的自定义组件,但我似乎无法找到任何有关如何这样做的好信息。我想要做的仅仅是在有Bindning属性主窗口中的自定义组件...WPF自定义组件Datagrid绑定
<local:MultiColumnComboBox ItemsSource="{Binding Customers}" x:Name="NewCombo"></local:MultiColumnComboBox>
然后在自定义组件...
<DataGrid ItemsSource="{Binding ItemsSource}" Name="dataGrid"></DataGrid>
如果有谁知道怎么样要做到这一点,一些指导,将不胜感激:)
编辑
public static readonly DependencyProperty ItemsSourceProperty =
DependencyProperty.Register("ItemsSource", typeof(IList<Customer>), typeof(MultiColumnComboBox));
public MultiColumnComboBox()
{
InitializeComponent();
}
//Items Source Binding
public IList<Customer> ItemsSource
{
get
{
return (IList<Customer>)GetValue(ItemsSourceProperty);
}
set
{
System.Console.WriteLine("Binding");
System.Console.WriteLine(value);
SetValue(ItemsSourceProperty, value);
}
}
您应该使用DependencyProperty。这是我见过的最完整,最易于理解的链接。 http://www.codeproject.com/Articles/224230/Exploring-the-use-of-Dependency-Properties-in-User – FodderZone
谢谢,我已经看到了这个,但在该项目**公共IEnumerable ItemsSource ** (我需要的部分)给出错误并要求您添加1个类型参数。 – Kapow36
另外,如果我使用推荐的** System.Collections.IEnumerable **它会给出错误**不能在'MultiColumnComboBox'类型的'ItemsSource'属性上设置'Binding'。 '绑定'只能在DependencyObject的DependencyProperty上设置。** – Kapow36