Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 91519

How to navigate to a new page

$
0
0

Hi,
I have write a android app using Xamarin.Forms, and I want to navigate a new page, the following is my code:
public class ListViewPage:ContentPage
{
public ListViewPage ()
{
var listView = new ListView {
RowHeight = 40
};
/listView.ItemsSource = new string[] {
"Buy pears",
"Buy oranges",
"Buy mangos",
"Buy apples",
"Buy bananas"
};
/
listView.ItemsSource = new TodoItem[] {
new TodoItem{Name = "Buy pears"},
new TodoItem{Name = "Buy oranges",Done = true},
new TodoItem{Name = "Buy mangos"},
new TodoItem{Name = "Buy apples",Done=true},
new TodoItem{Name = "Buy bananas",Done=true}
};
listView.ItemTemplate = new DataTemplate (typeof(TextCell));
listView.ItemTemplate.SetBinding(TextCell.TextProperty,"Name");
listView.ItemSelected += async (sender,e)=> {
var todoItem = (TodoItem)e.SelectedItem;
//await DisplayAlert("Tapped!",todoItem.Name+" was tapped.","OK","");
var todoPage = new TodoItemPage(todoItem);
await Navigation.PushAsync(todoPage);
};
Content = new StackLayout {
VerticalOptions = LayoutOptions.FillAndExpand,
Children = {listView}
};
}
}
public class TodoItem{
public string Name{get;set;}
public bool Done{get;set;}
}
But I got an exception, when the code runs to "await Navigation.PushAsync(todoPage);". Then exception details is:
Java.Lang.RuntimeException: java.lang.reflect.InvocationTargetException
at --- End of managed exception stack trace ---
at java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at at dalvik.system.NativeStart.main(Native Method)
at Caused by: java.lang.reflect.InvocationTargetException
at at java.lang.reflect.Method.invokeNative(Native Method)
at at java.lang.reflect.Method.invoke(Method.java:515)
at at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at ... 2 more
at Caused by: md52ce486a14f4bcd95899665e9d932190b.JavaProxyThrowable: System.InvalidOperationException: PushAsync is not supported globally on Android, please use a NavigationPage.
at at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw ()
at at System.Runtime.CompilerServices.AsyncMethodBuilderCore.m__0 (object)
at Android.App.SyncContext/c__AnonStorey0.<>m__0 () [0x00000] in /Users/builder/data/lanes/monodroid-mavericks-monodroid-5.1-series/d23da369/source/monodroid/src/Mono.Android/src/Android.App/SyncContext.cs:18
at Java.Lang.Thread/RunnableImplementor.Run () [0x0000b] in /Users/builder/data/lanes/monodroid-mavericks-monodroid-5.1-series/d23da369/source/monodroid/src/Mono.Android/src/Java.Lang/Thread.cs:36
at Java.Lang.IRunnableInvoker.n_Run (intptr,intptr) [0x00009] in /Users/builder/data/lanes/monodroid-mavericks-monodroid-5.1-series/d23da369/source/monodroid/src/Mono.Android/platforms/android-15/src/generated/Java.Lang.IRunnable.cs:71
at at (wrapper dynamic-method) object.fb707252-050e-45f5-8ec9-c19074c7f457 (intptr,intptr)
at at mono.java.lang.RunnableImplementor.n_run(Native Method)
at at mono.java.lang.RunnableImplementor.run(RunnableImplementor.java:29)
at at android.os.Handler.handleCallback(Handler.java:733)
at at android.os.Handler.dispatchMessage(Handler.java:95)
at at android.os.Looper.loop(Looper.java:136)
at at android.app.ActivityThread.main(ActivityThread.java:5017)
at ... 5 more
Please help me fix it...
Terry Guo


Viewing all articles
Browse latest Browse all 91519

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>