問題は、コンパイルされないことです。はからObservableCollection<T>
派生したものではないためDependencyObject
、コードの残りの部分を修正しても、この実装は機能しません。これも完全に間違っています。
詳細については、こちらDependencyProperties
をご覧ください。
編集
プロパティの正しい実装は次のようになります
public class SomeClass : DependencyObject
{
public static readonly DependencyProperty UrlProperty =
DependencyProperty.Register("Url", typeof(Uri), typeof(SomeClass));
public Uri Url
{
get { return (Uri)GetValue(UrlProperty);}
set { SetValue(UrlProperty, value); }
}
}
編集 2
ラッパーの実装
public class SomeClass : DependencyObject
{
public static readonly DependencyProperty UrlProperty =
DependencyProperty.Register("Url", typeof(Uri), typeof(SomeClass),
new PropertyMeta(OnUrlChanged));
public Uri Url
{
get { return (Uri)GetValue(UrlProperty);}
set { SetValue(UrlProperty, value); }
}
public ObservableCollection<Song> Songs { get; set; }
private static void OnUrlChanged (DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var wrapper = d as SomeClass;
if (wrapper == null)
return;
// ... what ever you want to do with the collection
}
}