I'm a beginner with .NET MAUI and I'm trying to pass a Picker value to an Icommand, but what I can receive is only this date 01/01/1900 The Icommand is fired but the date still 01/01/1900
This is my Xaml code:
<Picker
HeightRequest="40"
WidthRequest="150"
Grid.Row="1" Grid.Column="1"
BackgroundColor="Beige"
HorizontalOptions="Center"
HorizontalTextAlignment="Center"
Title="Seleziona Il Mese"
ItemsSource="{Binding Month}"
IsVisible="{Binding visible}"
>
<Picker.Behaviors>
<mct:EventToCommandBehavior
EventName="SelectedIndexChanged"
Command="{Binding SelectedMesi}"
EventArgsConverter="{StaticResource SelectedItemEventArgsConverter}"
CommandParameter="SelectedItem"
/>
</Picker.Behaviors>
And this is the viewModel
public DateTime datascelta { get; set; }
public ICommand SelectedMesi { get; }
public DateTime DataScelta
{
get => datascelta;
set
{
if(value == datascelta) return;
datascelta = value;
OnPropertyChanged();
}
}
internal void SelectedIndexChangeMese()
{
DataScelta = datascelta;
}
Where is the mistake?? Thx you.
You haven't set the
SelectedItemproperty for your Picker.Based on your code, I created a demo and achieved this function.You can refer to the following code:
MyViewModel .cs
Item.cs
MainPage.xaml
MainPage.xaml.cs
Note:
1.I can get the
MyViewModelfrom commandSelectedMesiCommand, and I can also get the updatedSelectedItem.2.In fact, you can also use DatePicker to achieve this.