public class ImageData
{
public int ImageIndex { get; set; }
public ImageSource ImgSource { get; set; }
public string SourceUrl { get; set; }
public DateTime CreateTime { get; set; }
public string ImageTitle { get; set; }
public string ImageClass { get; set; }
}
public partial class ImageListControl : UserControl
{
public static readonly DependencyProperty ImageDataListProperty = DependencyProperty.Register("ImageDataList",
typeof(System.Collections.ObjectModel.ObservableCollection<ImageData>), typeof(ImageListControl),
new FrameworkPropertyMetadata("NO DATA"));
public ImageListControl()
{
InitializeComponent();
}
public System.Collections.ObjectModel.ObservableCollection<ImageData> ImageDataList
{
get { return (System.Collections.ObjectModel.ObservableCollection<ImageData>)GetValue(ImageDataListProperty); }
set { SetValue(ImageDataListProperty, value); }
}
}
I the use UserControl registered DependencyProperty error.Why can not I register DependencyProperty ? I don’t know what is wrong. Please help me ,Thank you.
FrameworkPropertyMetadata‘s constructor takes an object as the first parameter. This object is the default value of your property. So the problem is that the string
"NO DATA"cannot be converted intoImageData. You can either providenullas the parameter or provide some appropriate instance ofImageDatawhichever looks more valid to you. I prefernullthough.