![](/img/trans.png)
[英]With an iOS custom renderer, is there a way I can make a question mark item appear in a TextCell and open up a dialog box?
[英]How can I make the Tapped event of a TextCell open up another page?
我已經定義了一個TextCell像這樣:
public partial class MyTextCell : TextCell
{
protected override void OnBindingContextChanged()
{
base.OnBindingContextChanged();
var item = BindingContext as CategoryGroupWordCountVM;
if (item != null)
{
this.Text = item.Name;
this.Detail = App.DB.GetTotalWordCountBySelectedCategories(item.Id).ToString();
this.StyleId = "disclosure";
}
}
}
我添加了一個添加點擊事件,如下所示:
section = new TableSection("Select from Available Categories");
foreach (var category in categoryGroups)
{
var cell = new CategoryGroupTextCell { BindingContext = category };
cell.Tapped += openCategoriesPage();
section.Add(cell);
}
}
tableView.Root.Add(section);
我有一個openCategoriesPage方法:
async void openCategoriesPage(object sender, ItemTappedEventArgs e)
{
if (e.Item == null) return;
var categoriesPage = new CategoriesPage();
var categoryGroup = e.Item as CategoryGroupWordCountVM;
((ListView)sender).SelectedItem = null;
await Navigation.PushAsync(categoriesPage);
}
但是我有一個問題,我得到一個錯誤,說:
CategoryGroupPage.xaml.cs(36,36):錯誤CS7036:沒有給出與“ CategoryGroupPage.openCategoriesPage(object,ItemTappedEventArgs)”的所需形式參數“ sender”相對應的參數
有人可以告訴我我是否正確執行了下一頁的打開操作,這又可能是導致我出錯的原因嗎?
您應該僅使用方法名稱(不帶括號)訂閱Tapped事件,如下所示:
cell.Tapped += openCategoriesPage;
與執行以下操作相同:
cell.Tapped += new EventHandler(openCategoriesPage);
編譯器將為這兩者生成相同的IL代碼,但是如果您想在將來取消訂閱事件處理程序,則第一個更有意義(您很可能會這樣做)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.