WPF - How do I use the UserControl with a dependency property and view model?
Posted
by user320849
on Stack Overflow
See other posts from Stack Overflow
or by user320849
Published on 2010-04-20T17:31:58Z
Indexed on
2010/04/20
17:33 UTC
Read the original article
Hit count: 263
Hello,
My goal is to have a user select a year and a month. Translate the selection into a date and have the user control send the date back to my view model. That part works for me....However, I cannot get the ViewModel's initial date to set those drop downs.
public static readonly DependencyProperty Date =
DependencyProperty.Register("ReturnDate", typeof(DateTime), typeof(DatePicker),
new FrameworkPropertyMetadata{BindsTwoWayByDefault = true,});
public DateTime ReturnDate
{
get { return Convert.ToDateTime(GetValue(Date)); }
set
{
SetDropDowns(value);
SetValue(Date, value);
}
}
The SetDropDowns(value) just sets the selected items on the combo boxes, however, the program never makes it to that method.
On the view I am using:
<cc1:DatePicker ReturnDate="{Binding Path=StartDate, Mode=TwoWay}" IsStart="True" />
If this has been answered, then my bad. I looked around and didn't see anything that worked for me. Thus, when the program loads how do I get the value from the view model to a method in order to set the combo boxes?
Thanks,
-Scott
© Stack Overflow or respective owner