I have a usercontrol consisting of two DateTimePicker This component must be reusable and should expose properties which define, for example, the Visibility of elements, the WIDTH of the container, etc.. And of course, I'm able to retrieve the values entered.
So I created adequate 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));
When I use my UserControl into a view, I do not know how to get in my viewmodel, the values entered in the DatePicker of my usercontrol.
My userControl:
<my:myDateTimePicker StartDateValue="{Binding StartDateDebut, Mode=TwoWay}" x:Name="myPeriod" />
And my Button:
<Button Content="Ok" Width="75" Height="20" Command="{Binding Path=SaveCommand, Mode=OneTime}"/>
Thanks, PM