Come nota a margine, è anche la pena notare che si ottengono questi errori vincolanti se si copia e incolla tra gli oggetti e dimenticare di modificare la seconda typeof(Object)
dichiarazione.
Non riuscivo a capire per un'ora buona perché stavo ottenendo questo errore come tutto sembrava essere definito e corretto. Ho spostato le mie proprietà in un controllo utente perché volevo passare da un singolo set a un elenco. Così:
public static readonly DependencyProperty FoldersProperty = DependencyProperty.Register("Folders", typeof(OutlookFolders), typeof(MainWindow), new FrameworkPropertyMetadata(new OutlookFolders()));
public OutlookFolders Folders
{
get { return GetValue(FoldersProperty) as OutlookFolders; }
set { SetValue(FoldersProperty, value); }
}
dovuto diventare:
public static readonly DependencyProperty FoldersProperty = DependencyProperty.Register("Folders", typeof(OutlookFolders), typeof(SavedFolderControl), new FrameworkPropertyMetadata(new OutlookFolders()));
public OutlookFolders Folders
{
get { return GetValue(FoldersProperty) as OutlookFolders; }
set { SetValue(FoldersProperty, value); }
}
Fino a quando ho fatto questo cambiamento ho continuato a ricevere l'errore: A 'Binding' cannot be set on the property 'Folders' of type 'SavedFolderControl'. A 'Binding' can only be set on a DependencyProperty of a DependencyObject.
Sì.Solo le proprietà di dipendenza possono fungere da target per i binding. L'origine può essere una proprietà di dipendenza o una proprietà CLR che implementa INotifyPropertyChanged – Gishu
Questo è un duplicato esatto di un'altra domanda, in cui si accetta una risposta e si dice "ma ho dovuto modificare la proprietà per includere DependencyProperty". La tua soluzione avrebbe dovuto essere inclusa come risposta lì – arserbin3
@AdamHouldsworth Sì, questa domanda è stata pubblicata solo per pubblicare la risposta. Questo è in realtà incoraggiato in quanto è visto come una forma di condivisione della conoscenza, e c'è anche un [nuovo 'CheckBox' nel modulo Domanda Ask] (http://meta.stackexchange.com/questions/132886/what-is- this-answer-your-own-question-jazz) che ti permetterà di scrivere una risposta nello stesso momento in cui scrivi la tua domanda. – Rachel