I have a view that allows the user to select some data : some dates for example, and executes a command that needs these data.
So in my command I should have a reference to the selected date, but what is the best practice to make this date go to the ViewModel side where the command lives :
- to add a SelectedDate dependency property in the ViewModel and bind my view on it, and reference it in my command via “@this.SelectedDate” (with @this a reference to the current ViewModel),
- to let the view transmit it through the “parameter” of the “Execute” method of the command, and reference the date with “DateTime selectedDate = (DateTime)parameter;”,
- any other solution…
Thanks by advance.
I’d make
SelectedDatea dependency property of the view model, absolutely.I’d also make the command get the
SelectedDatefrom the view model. There’s no reason for the view to know anything about that.