EventToCommand behavior exception on telerik Xamarin UI rad controls

3 posts, 0 answers
  1. Gilberto
    Gilberto avatar
    67 posts
    Member since:
    Sep 2006

    Posted 20 Apr Link to this post

    hi

     

    I´ve got a exception, when i use this nuget package (https://github.com/corradocavalli/Corcav.Behaviors) to achieve event to command behavior. In code bellow i also have a regular Listview and works great. Does radcontrols have something special in events or i´m missing something

    View Model code:

    private Command _dataSelecionadaCommand;
           public Command DataSelecionadaCommand
           {
               get
               {
                   return _dataSelecionadaCommand ?? new Command(() =>
             {
               // do something
             });
               }
           }

     

    XAML code:

    <telerikInput:RadCalendar SelectedDate="{Binding DiaSelecionado}"  AppointmentsSource="{Binding Provas}" >
                   <!--<behaviors:Interaction.Behaviors>
                       <behaviors:BehaviorCollection>
                           <behaviors:EventToCommand EventName="SelectionChanged" Command="{Binding DataSelecionadaCommand}" />
                       </behaviors:BehaviorCollection>
                   </behaviors:Interaction.Behaviors>-->
               </telerikInput:RadCalendar>
               <ListView  Grid.Row="1" ItemsSource="{Binding Provas}">
                   <behaviors:Interaction.Behaviors>
                       <behaviors:BehaviorCollection>
                           <behaviors:EventToCommand EventName="ItemSelected" Command="{Binding DataSelecionadaCommand}" />
                       </behaviors:BehaviorCollection>
                   </behaviors:Interaction.Behaviors>
                   <ListView.ItemTemplate>
                       <DataTemplate>
                           <ViewCell>
                               <Grid Padding="10">
                                   <Grid.RowDefinitions>
                                       <RowDefinition Height="*"></RowDefinition>
                                       <RowDefinition Height="*"></RowDefinition>
                                   </Grid.RowDefinitions>
                                   <Label Text="{Binding StartDate}"></Label>
                                   <Label Text="{Binding EndDate}" Grid.Row="1"></Label>
                               </Grid>
                           </ViewCell>
                       </DataTemplate>
                   </ListView.ItemTemplate>
               </ListView>

     

     

    This is the exception : 'No command available, Is Command properly set up?'

    The command instantiation is in the getter, checking if is null, and the regular listview works.

     

    Thanks

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

  2. Nikolay Demirev
    Admin
    Nikolay Demirev avatar
    136 posts

    Posted 21 Apr Link to this post

    Hello Gilberto,

    I have tested your scenario. And I have found out that the RadCalendar is firing SelectionChanged when the BindingContext of the page changes because the selected date is updated using the value from the ViewModel. This is causing the EventToCommand to handle the event and try to execute the command. But there is the following check in the code:
    if (this.Command == null) throw new InvalidOperationException("No command available, Is Command properly set up?");

    By that time the Command property is still not initialized. I believe it is not initialized because the bindings update their values in the same order as they are declared in the XAML. That means that first the SelectionDate will be updated and then the Command will be set.

    After removing the line checking if the Command is null everything works perfectly. I suggest you remove that check from the EventToCommand implementation.

    If you do not want to change the code of the EventToCommand class you could update your ViewModel, so its initial value for the selected date property is null because the default value of the SelectedDate property of the RadCallendar is null and this will not cause the SelectionChanged event to fire.

    I hope this helps.

    Regards,
    Nikolay Demirev
    Telerik by Progress
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. Gilberto
    Gilberto avatar
    67 posts
    Member since:
    Sep 2006

    Posted 22 Apr in reply to Nikolay Demirev Link to this post

    Thank you

     

    it does make sense, i will try

     

     

Back to Top