I have a TimePicker and I try when the time change to call a command, but it doesn't work.
This is the code:
[ObservableProperty]
[NotifyCanExecuteChangedFor(nameof(TimeSelectedCommand))]
TimeSpan startTime;
[ObservableProperty]
[NotifyCanExecuteChangedFor(nameof(TimeSelectedCommand))]
TimeSpan endTime;
[RelayCommand]
private void TimeSelected()
{
if (StartTime != null && EndTime != null && StartTime < EndTime)
{
Preview.NumberOfSelectedIntervals = (int)(EndTime.Hours - StartTime.Hours);
}
}
An the code for XAML:
<Border Style="{StaticResource TimePickerBorderStyle}">
<TimePicker Style="{StaticResource TimePickerStyle}"
Time="{Binding StartTime}" />
</Border>
<Border Grid.Column="2"
Style="{StaticResource TimePickerBorderStyle}">
<TimePicker Time="{Binding EndTime}"
Style="{StaticResource TimePickerStyle}" />
</Border>
{Binding StartTime}orEndTime, or other syntax. 3) Maybe the binding between View and ViewModel isn't set up. Add link to doc or example that you based this on? 4) What are the names of the View and ViewModel classes?