0
我有一个由两个DateTimePicker组成的用户控件 此组件必须是可重用的,并且应该公开定义例如元素的可见性,容器的宽度等属性。 当然,我可以检索输入的值。检索通过usercontrol输入的值
所以我创造了足够的DependencyProperty
public DateTime StartDateValue
{
get { return (DateTime)GetValue(StartDateValueProperty); }
set { SetValue(StartDateValueProperty, value); }
}
// Using a DependencyProperty as the backing store for StartDateValue. This enables animation, styling, binding, etc...
public static readonly DependencyProperty StartDateValueProperty =
DependencyProperty.Register("StartDateValue", typeof(DateTime), typeof(HSWDateTimePicker), new PropertyMetadata(HSWDateTimePicker.StartDateValueChanged));
当我使用我的用户到视图,我不知道如何在我的视图模型得到的,在我的用户的DatePicker的输入值。
我的用户:
<my:myDateTimePicker StartDateValue="{Binding StartDateDebut, Mode=TwoWay}" x:Name="myPeriod" />
我的按钮:
<Button Content="Ok" Width="75" Height="20" Command="{Binding Path=SaveCommand, Mode=OneTime}"/>
感谢,PM
谢谢你的答案,但我不希望我的用户控件的DataContext目标为特定的VIEWMODEL。 因为我的UserControl必须是可重用的。 我实际上找到了这个链接的解决方案: http://stackoverflow.com/questions/1526767/silverlight-usercontrol-custom-property-binding – Zorg 2010-08-28 17:07:34