Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Time Picker Value not Binging with View model In MAUI .net

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

>Solution :

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading