数据绑定自定义WPF控件不起作用

时间:2014-09-09 08:43:38

标签: wpf

我为DateTimePicker编写了一个自定义控件,但绑定值没有正确传递给属性。

<cc:DateTimePicker SelDate="{Binding RA_EFFECTIVE_DATE}"/> <!-- Doesn't work -->
<cc:DateTimePicker SelDate="1.1.2014"/> <!-- Works? Which means I can see the value inside setter SelDate correctly -->

这是我的DateTimePicker类:​​

    public static readonly DependencyProperty SelDateProperty =
       DependencyProperty.Register(
       "SelDate",
       typeof(DateTime?),
       typeof(DateTimePicker),
       new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnSelectedDateChanged, CoerceSelectedDate));



    public DateTime? SelDate
    {
        get { return (DateTime?)GetValue(SelDateProperty); }
        set { SetValue(SelDateProperty, value); }
    }

提前致谢...

0 个答案:

没有答案