I recommend the community toolkit mvvm. It provides a relaycommand implementation of icommand, messenger, base classes and does code generation.
https://learn.microsoft.com/en-us/dotnet/communitytoolkit/mvvm/
Here's a quick sample to give you the idea of how this could work:
<StackPanel>
<DatePicker Name="DateSelection"
SelectedDate="{Binding DateSelected}"/>
<Button Content="DoSomething"
Command="{Binding DateChosenCommand}"
CommandParameter="{Binding SelectedDate, ElementName=DateSelection}"/>
</StackPanel>
And the viewmodel:
public partial class MainWindowViewModel : ObservableObject
{
private readonly JiraHandler jiraHandler;
[ObservableProperty]
private DateTime? dateSelected;
partial void OnDateSelectedChanged(DateTime? newDate)
{
// Fires when bound Date value changes
}
[RelayCommand]
private void DateChosen(DateTime? selectedDate)
{
if (selectedDate != null)
{
dateSelected = (DateTime)selectedDate;
}
}
[ObservableProperty]
private ObservableCollection<Issue> issues = new ObservableCollection<Issue>();
public MainWindowViewModel(JiraHandler jiraHandler)
{
this.jiraHandler = jiraHandler;
}
You should use DateSelected from the datepicker. That is a nullable DateTime?
You could potentially bind that selected date and the command references that value.
Notes:
Aways implement inotifypropertychanged on any viewmodel ( to avoid memory leaks. ) The ObservableObject does so. There is also a ObservableValidator which gives validation support.
The public properties are generated in another partial class file.
You automatically get methods you can provide for property changed or propertychanging. This allows you to conveniently act when say the date is selected in your datepicker.