Error Exception has been thrown by the target of an invocation

1 Answer 1323 Views
BusyIndicator
Hugo
Top achievements
Rank 1
Hugo asked on 12 Dec 2018, 12:28 AM

Hi, I have a problem when using BusyIndicator. I mark the following error when I want to change its status to false

 

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation

 

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:telerikInput="clr-namespace:Telerik.XamarinForms.Input;assembly=Telerik.XamarinForms.Input"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:ONControl_Mobile.CUST.VinculoCultural"
             xmlns:telerikInputDataForm="clr-namespace:Telerik.XamarinForms.Input.DataForm;assembly=Telerik.XamarinForms.Input"
             xmlns:telerikPrimitives="clr-namespace:Telerik.XamarinForms.Primitives;assembly=Telerik.XamarinForms.Primitives"
             x:Class="ONControl_Mobile.CUST.VinculoCultural.VCPA_AutorizacionContratoDetail"
             BackgroundColor="White">
    <telerikPrimitives:RadBusyIndicator x:Name="BusyIndicator"
                                        AnimationContentHeightRequest="150"
                                        AnimationContentWidthRequest="150"  
                                        AnimationType="Animation3"
                                        AnimationContentColor="#4E6F99">

        <telerikPrimitives:RadBusyIndicator.BusyContent>
            <Label Text="Cargando..."  HorizontalOptions="Center" HorizontalTextAlignment="Center"/>
        </telerikPrimitives:RadBusyIndicator.BusyContent>
        <telerikPrimitives:RadBusyIndicator.Content>

            <ScrollView>
                <AbsoluteLayout  HorizontalOptions="FillAndExpand"  BackgroundColor="White">
                        <StackLayout Padding="5,5,5,10">
                    <!--<ScrollView>-->
                        <Grid VerticalOptions="Start">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="18" />
                                <RowDefinition Height="40" />
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="5*" />
                                <ColumnDefinition Width="5*" />
                            </Grid.ColumnDefinitions>


                            <Label x:Name="LB_Folio"  Text="Folio:" Grid.Row="0" Grid.Column="0"  HorizontalOptions="FillAndExpand" Font="12" TextColor="Black" FontAttributes="Bold" Margin="5,0,0,0"/>
                            <Label x:Name="LB_Fecha" Text="Fecha:" Grid.Row="0" Grid.Column="1" HorizontalOptions="End" Font="12" TextColor="Black" FontAttributes="Bold" Margin="0,0,5,0"/>

                            <telerikInput:RadEntry x:Name="TB_ClienteDescripcion"
                                                   TextColor="Black"
                                                   FontSize="19"
                                                   Text="Cliente"
                                                   Grid.Row="1" 
                                                   Grid.Column="0" 
                                                   Grid.ColumnSpan="2"
                                                   HorizontalOptions="FillAndExpand"
                                                   VerticalTextAlignment="Center"
                                                   Opacity="70"
                                                   BorderStyle="{StaticResource EntryBorderStyle}"
                                                   IsEnabled="False"/>
                        </Grid>

                        <!-- Se pinta Dataform-->
                        <telerikInput:RadDataForm x:Name="RDF_Contrato" 
                                              Margin="5,5,0,0"    
                                              ValidationMode="Manual">
                            <telerikInput:RadDataForm.Source>
                                <local:VCPA_ContratoSource />
                            </telerikInput:RadDataForm.Source>
                            <telerikInput:RadDataForm.GroupHeaderStyle>
                                <telerikInputDataForm:DataFormGroupHeaderStyle Background="Gainsboro" Foreground="Black" Height="55" Padding="10" TextAlignment="Center" />
                            </telerikInput:RadDataForm.GroupHeaderStyle>
                        </telerikInput:RadDataForm>

                        <!--Spinner-->
                        <Label Text="Seleccionar Estado" FontSize="12" TextColor="#424242" FontAttributes="Bold" Font="Arial"></Label>
                        <Picker x:Name="P_Estado"
                                Grid.Row="2" 
                                Grid.Column="0"  
                                Grid.ColumnSpan="2"  
                                HorizontalOptions="FillAndExpand"
                                FontSize="Small" 
                                VerticalOptions="Start" 
                                TextColor="Gainsboro" 
                                SelectedIndexChanged="P_Estado_SelectedIndexChanged"/>

                        <Label Text="Seleccionar Ciudad" FontSize="12" TextColor="#424242" FontAttributes="Bold" Font="Arial"></Label>
                        <Picker x:Name="P_Ciudad"
                                Grid.Row="3" 
                                Grid.Column="0"  
                                Grid.ColumnSpan="2"  
                                HorizontalOptions="FillAndExpand" 
                                FontSize="Small" 
                                VerticalOptions="Start" 
                                TextColor="Gainsboro" 
                                SelectedIndexChanged="P_Ciudad_SelectedIndexChanged"/>

                        <!--Grabar Documento-->
                        <telerikInput:RadButton x:Name="B_Autorizar" 
                                                Text="Autorizar Contrato" 
                                                Clicked="B_Autorizar_Clicked" 
                                                FontSize="12" 
                                                TextColor="Black"/>

                        <!--</ScrollView>-->
                    </StackLayout>
                </AbsoluteLayout>
            </ScrollView>
        </telerikPrimitives:RadBusyIndicator.Content>
    </telerikPrimitives:RadBusyIndicator>   
</ContentPage>

1 Answer, 1 is accepted

Sort by
0
Lance | Manager Technical Support
Telerik team
answered on 12 Dec 2018, 12:45 AM
Hello Hugo,

Although I can't directly replicate the exception, I have a suspicion the problem because of the Content of the BusyIndicator.  When using data bound or x:Named elements, it is better to put the BusyIndicator on top of the content.

This is because when you set IsBusy=False, all the elements inside RadBusyIndicator.Content are removed from the visual tree. This can cause issues with databinding, or if you have other logic that is relying on x:Named elements being in the tree.

Do the following instead:

<ContentPage ...>
    <Grid>
        <ScrollView>
            <!-- Your page content -->
         </ScrollView>
          
         <!-- Busy Indicator on top of the content -->
         <telerikPrimitives:RadBusyIndicator
                x:Name="BusyIndicator"
                BackgroundColor="#CCFFFFFF"
                AnimationContentHeightRequest="150"
                AnimationContentWidthRequest="150" 
                AnimationType="Animation3"
                AnimationContentColor="#4E6F99">
            <telerikPrimitives:RadBusyIndicator.BusyContent>
                <Label Text="Cargando..."  HorizontalOptions="Center" HorizontalTextAlignment="Center"/>
            </telerikPrimitives:RadBusyIndicator.BusyContent>
        </telerikPrimitives:RadBusyIndicator
    </Grid>
</ContentPage>

Then, when you change IsBusy, also set IsVisible at the same time so that you don't block user gestures:

BusyIndicator.IsVisible = true;
BusyIndicator.IsBusy = true;
  
// do work
  
BusyIndicator.IsBusy = false;
BusyIndicator.IsVisible = false;


Regards,
Lance | Tech Support Engineer, Sr.
Progress Telerik
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
Tags
BusyIndicator
Asked by
Hugo
Top achievements
Rank 1
Answers by
Lance | Manager Technical Support
Telerik team
Share this question
or