Issue
I'm having a problem coding right now on my Xamarin.Forms application. I have a list view with a StackLayout in it (worked well). But when I saw SwipeView existed, I updated to the lastest version of Xamarin.Forms (4.4.0.991640) and made this xaml code :
<StackLayout Grid.Row="0" Grid.Column="2" Grid.RowSpan="2" BackgroundColor="LightGray">
<ListView x:Name="ItemsListView"
ItemsSource="{Binding Items}"
VerticalOptions="FillAndExpand"
HasUnevenRows="true"
RefreshCommand="{Binding LoadItemsCommand}"
IsPullToRefreshEnabled="true"
IsRefreshing="{Binding IsBusy, Mode=OneWay}"
CachingStrategy="RecycleElement"
ItemSelected="OnItemSelected">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<SwipeView>
<SwipeView.RightItems>
<SwipeItems>
<SwipeItem Text="Favorite"
BackgroundColor="LightGreen"
Invoked="OnModifySwipeItemInvoked" />
<SwipeItem Text="Delete"
BackgroundColor="LightPink"
Invoked="OnDeleteSwipeItemInvoked" />
</SwipeItems>
</SwipeView.RightItems>
<SwipeView.Content>
<StackLayout Padding="10" BackgroundColor="{Binding ColorCode}">
<Label Text="{Binding Type}"
d:Text="{Binding .}"
LineBreakMode="NoWrap"
Style="{DynamicResource ListItemTextStyle}"
FontSize="Large"
HorizontalOptions="Center"/>
<Label Text="{Binding Description}"
d:Text="Item descripton"
LineBreakMode="NoWrap"
Style="{DynamicResource ListItemDetailTextStyle}"
FontSize="Medium"
HorizontalOptions="Center"/>
</StackLayout>
</SwipeView.Content>
</SwipeView>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
At first I have no items, so it doesn't crash. But at soon as I add an item, so that I return to this page, I have the exception :
System.Reflection.TargetInvocationException: 'Exception has been thrown by the target of an invocation.'
No try catches possible because it happens when I come back to page and I tried with unhandleexception but still didn't get more informations...
If you need more info, please ask me. Can you please help me? Thanks!
Solution
System.Reflection.TargetInvocationException: 'Exception has been thrown by the target of an invocation.'
SwipeView
is available in Xamarin.Forms 4.4. However, it's currently experimental and can only be used by adding the following line of code to your AppDelegate
class on iOS, to your MainActivity
class on Android, or to your App
class on UWP, before calling Forms.Init
:
Forms.SetFlags("SwipeView_Experimental");
(If no, it will occur the same error.)
For example in Android :
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
Forms.SetFlags("SwipeView_Experimental"); // Add here
global::Xamarin.Forms.Forms.Init (this, bundle);
LoadApplication (new App ());
}
}
In iOS :
public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
{
public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{
Forms.SetFlags("SwipeView_Experimental"); // Add here
global::Xamarin.Forms.Forms.Init ();
LoadApplication (new App ());
return base.FinishedLaunching (app, options);
}
}
If want to know more ,you can have a look at this Xamarin.Forms SwipeView .
Answered By - Junior Jiang
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.