按钮无法导航到Xamarin窗体中的另一个页面
本文关键字:另一个 窗体 Xamarin 导航 按钮 | 更新日期: 2023-09-27 18:06:42
我有以下ListView在我的页面。
ListView listof_datewiseRecord = new ListView {
BackgroundColor=ColorResources.PageBackgroundColor,
ItemTemplate = new DataTemplate (typeof(dataCell)),
ItemsSource = listofdate,
RowHeight=70,
};
public class dataCell:ViewCell
{
public dataCell ()
{
var btnDetails = new Button () {
FontFamily = "HelveticaNeue-Medium",
FontSize = 13,
WidthRequest=60,
TextColor = ColorResources.TextColor,
Text="Details",
BackgroundColor=Color.Blue,
HeightRequest=35,
VerticalOptions = LayoutOptions.CenterAndExpand,
HorizontalOptions = LayoutOptions.CenterAndExpand
};
btnDetails.Clicked += async (object sender, EventArgs e) => {
await this.Navigation.PushAsync(new AdminHome());//I am getting problem here to navigate to other page.
}
我想导航到另一个页面的点击事件的btnDetails。但我无法找到导航的定义在点击事件。为什么会这样?如何解决?
这里的问题是,一个ListView
有它自己的点击处理程序(ListView.ItemTapped
和ListView.ItemSelected
)或只是使用那些而不是你的Button
和代替Button
与Label
或类似的东西。
如果你仍然想使用Button
,你需要使ListView
处理程序无效,以使点击工作。
试着添加这个:
listof_datewiseRecord.ItemSelected += (sender, e) => {
((ListView)sender).SelectedItem = null;
};
另外,根据Xamarin Forms参考Button
s在ListView
s这里你可能需要创建一个自定义的Android渲染器