所以,我試圖執行一些數據綁定到我有的自定義組件,但我似乎無法找到任何有關如何這樣做的好信息。我想要做的僅僅是在有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