MasterDetailPage 仅在第一次点击时导航

MasterDetailPage navigate only first click

我实现了 MasterDetailPage:

public MasterPage()
{menuList = new List<Models.MasterPageItem>();
var index= new Models.MasterPageItem() { Title = "index", Icon =index.png, TargetType = typeof(Index.Index) };
var client= new Models.MasterPageItem() { Title = "Clients", Icon =client.png, TargetType = typeof(Login.Client) };
menuList.Add(index);
menuList.Add(client);
navigationDrawerList.ItemsSource = menuList;
Detail = new NavigationPage((Page)Activator.CreateInstance(typeof(Dashboard)));
 }
private void OnMenuItemSelected(object sender, SelectedItemChangedEventArgs e){
Type page = item.TargetType;
Detail.Navigation.PushAsync((Page)Activator.CreateInstance(page));
IsPresented = false;
 }

问题是,如果我点击客户端,导航有效,但如果我按回键它也有效,问题是当我再次点击客户端时,dosent 工作,我必须在索引或其他项目上导航,并且单击客户端,我无法在同一项目上导航两次。

顾名思义,SelectedItemChanged 仅在 更改 时触发。因此,如果您连续两次点击同一个选项,它只会触发一次。解决方法是设置

navigationDrawerList.SelectedtedItem = null;

在您 havigate 之前的事件处理程序中