This is a migrated thread and some comments may be shown as answers.

EventToCommand behavior exception on telerik Xamarin UI rad controls

2 Answers 276 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Gilberto
Top achievements
Rank 1
Gilberto asked on 20 Apr 2017, 07:50 AM

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 Answers, 1 is accepted

Sort by
0
Nikolay Demirev
Telerik team
answered on 21 Apr 2017, 09:02 AM
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
0
Gilberto
Top achievements
Rank 1
answered on 23 Apr 2017, 01:06 AM

Thank you

 

it does make sense, i will try

 

 

Tags
General Discussions
Asked by
Gilberto
Top achievements
Rank 1
Answers by
Nikolay Demirev
Telerik team
Gilberto
Top achievements
Rank 1
Share this question
or