我创建了一个自定义的Silverlight控件,由两个日期选择器和一个组合框组成。 我想让组合框可数据绑定,我知道我需要使用DependencyProperty。 但我不确定如何构建它。 这是我目前的代码:
#region ItemsSource (DependencyProperty)
/// <summary>
/// ItemsSource to bind to the ComboBox
/// </summary>
public IList ItemsSource
{
get { return (IList)GetValue(ItemsSourceProperty); }
set { SetValue(ItemsSourceProperty, value); }
}
public static readonly DependencyProperty ItemsSourceProperty =
DependencyProperty.Register("ItemsSource", typeof(int), typeof(DateRangeControl),
new PropertyMetadata(0));
#endregion
问题在于,我看到的所有示例都是针对简单属性(如Text或Background),这些属性期望的是字符串、整数或颜色。由于我正在尝试绑定到组合框的ItemsSource,它期望的是IEnumerable,我不知道如何构建此属性。因此,我使用了IList。
请问有人能告诉我我是否走在正确的道路上,并给我一些指导吗?谢谢。