Command breaks

Eduardo Gomez Romero 1,375 Reputation points
2024-10-24T11:17:04.0233333+00:00
 <mct:EventToCommandBehavior
     Command="{Binding ConfirmDateCommand, Source={x:RelativeSource AncestorType={x:Type vm:TurbinesCollectionPageViewModel}}}"
     CommandParameter="{Binding Source={x:Reference picker}, Path=SelectedDate}"
     EventName="OkButtonClicked" />

System.InvalidOperationException: 'Operation is not valid due to the current state of the object.'

StackTrace = " at Microsoft.Maui.Controls.Binding.<ApplyRelativeSourceBinding>d__27.MoveNext()\r\n at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__128_0(Object state)\r\n at Microsoft.UI.Dispatching.DispatcherQueueSynchronizationContext.<>c__DisplayClass2_0.<Post>b__0()", Source = "Microsoft.Maui.Controls", Message = "Operation is not valid due to the current state of the object.", InnerException = null, HelpLink = null, HResult = -2146233079, Data = {System.Collections.ListDictionaryInternal}

     [RelayCommand]
     void ConfirmDate(DateTime dateTime) {

         if (DateTimePicker != null) {

             currentCulture = new CultureInfo(deviceLanguageService.GetDeviceLanguage());

             Turbine!.InstalationDateTime = dateTime;

             DateTimePicker.IsOpen = false;

             Turbine.StringifyInstalationDate = Turbine.InstalationDateTime?.ToString("D", currentCulture)!;

         }
     }

Developer technologies | .NET | .NET MAUI
{count} votes

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.