I'm Trying to Bind Time picker value with View model using Communitytook.mvvm. But my picker value is not getting it displays 12.00 AM continuously.
Xaml file
<TimePicker
Time="{Binding Time1,Mode=TwoWay}"
FontSize="Medium"
Grid.Column="0"
Grid.Row="1"
x:Name="time1"
IsEnabled="{Binding Time1IsEnabled,Mode=TwoWay}"/>
<TimePicker
Time="{Binding Time2,Mode=TwoWay}"
FontSize="Medium"
Grid.Column="1"
Grid.Row="1"
x:Name="time2"
IsEnabled="{Binding Time2IsEnabled,Mode=TwoWay}"/>
Viewmodel.cs
namespace CRUDappMAUI.ViewModel { public partial class AddLeaveViewModel : ObservableObject {
[ObservableProperty]
DateTime _time1;
[ObservableProperty]
DateTime _time2;
[RelayCommand]
public async void SubmitClicked()
{
try
{
Debug.WriteLine(_time1);
Debug.WriteLine(_time2);
}
catch (Exception ex) {
Debug.WriteLine(ex.ToString());
}
}
}
}
I'm expecting to get the time picker values to the View Mode.
CodePudding user response:
The Time
property of TimePicker
expects a TimeSpan
typed value so you should change the type properties in your view model to TimeSpan
. Check this