public QuestionsDetailsPage(Questions questions) { this.questions = questions; InitializeComponent(); BindingContext = new QuestionsDetailsViewModel(questions); var cancel = new ToolbarItem { Text = "分享", Command = new Command(() => { DependencyService.Get <IShares>().Shares("https://q.cnblogs.com/q/" + questions.Qid + "/", questions.Title); }) }; ToolbarItems.Add(cancel); if (Device.Android == Device.RuntimePlatform) { cancel.Icon = "toolbar_share.png"; } this.QuestionsDetailsView.ItemSelected += async delegate { var answers = QuestionsDetailsView.SelectedItem as QuestionsAnswers; if (answers == null) { return; } var answersDetails = new AnswersDetailsPage(answers); if (answers.AnswerID > 0) { await NavigationService.PushAsync(Navigation, answersDetails); } this.QuestionsDetailsView.SelectedItem = null; }; }
public QuestionsDetailsPage(Questions questions) { InitializeComponent(); Xamarin.Forms.PlatformConfiguration.iOSSpecific.Page.SetUseSafeArea(this, true); this.questions = questions; BindingContext = new QuestionsDetailsViewModel(questions); if (Device.Android == Device.RuntimePlatform) { var cancel = new ToolbarItem { Text = "分享", Command = new Command(() => { DependencyService.Get <IShares>().Shares("https://q.cnblogs.com/q/" + questions.Qid + "/", questions.Title); }), Icon = "toolbar_share.png" }; ToolbarItems.Add(cancel); } formsWebView.OnContentLoaded += delegate(object sender, EventArgs e) { RefreshQuestions(); }; formsWebView.AddLocalCallback("reload", async delegate(string obj) { if (formsWebView.LoadStatus == LoadMoreStatus.StausDefault || formsWebView.LoadStatus == LoadMoreStatus.StausError || formsWebView.LoadStatus == LoadMoreStatus.StausFail) { var questionsComments = JsonConvert.SerializeObject(await ViewModel.ReloadAnswersAsync()); await formsWebView.InjectJavascriptAsync("updateComments(" + questionsComments + ");"); } }); formsWebView.AddLocalCallback("editItem", delegate(string id) { var questionsAnswers = ViewModel.QuestionsAnswers.Where(n => n.AnswerID == int.Parse(id)).FirstOrDefault(); Device.BeginInvokeOnMainThread(async() => { var page = new QuestionsAnswersPopupPage(questions, new Action <QuestionsAnswers>(OnResult), questionsAnswers); await Navigation.PushPopupAsync(page); }); }); formsWebView.AddLocalCallback("deleteItem", async delegate(string id) { var result = await ViewModel.DeleteQuestionAnswersAsync(int.Parse(id)); await formsWebView.InjectJavascriptAsync("deleteComment(" + id + "," + result.ToString().ToLower() + ");"); }); formsWebView.AddLocalCallback("itemSelected", delegate(string id) { var questionsAnswers = ViewModel.QuestionsAnswers.Where(n => n.AnswerID == int.Parse(id)).FirstOrDefault(); Device.BeginInvokeOnMainThread(async() => { var answersDetails = new AnswersDetailsPage(questionsAnswers); if (questionsAnswers.AnswerID > 0) { await NavigationService.PushAsync(Navigation, answersDetails); } }); }); }