每当我从任何页面导航到地图页面时,地图页面都会闪烁起来,显示一点然后消失,然后带我回到开始的页面。
我最近解决了以前的导航视图问题,因为它根本无法导航。如您所见,我有两个不同的switch语句用于导航,这可能是问题所在,但在其他任何地方都不会发生。
主页C#代码:
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
}
private void NavView_Loaded(object sender, RoutedEventArgs e)
{
foreach (NavigationViewItemBase item in NavView.MenuItems)
{
if (item is NavigationViewItem && item.Tag.ToString() == "Home")
{
NavView.SelectedItem = item;
break;
}
}
}
private void NavView_ItemInvoked(NavigationView sender, NavigationViewItemInvokedEventArgs args)
{
if (args.IsSettingsInvoked)
{
Frame.Navigate(typeof(SettingsPage));
}
else
{
switch (args.InvokedItem)
{
case "Home":
Frame.Navigate(typeof(MainPage));
break;
case "Attractions":
Frame.Navigate(typeof(AttractionsPage));
break;
case "Places to Eat":
Frame.Navigate(typeof(PlacestoEatPage));
break;
case "Map":
Frame.Navigate(typeof(BlankPage1));
break;
case "Photos":
Frame.Navigate(typeof(Photos_Page));
break;
case "News":
Frame.Navigate(typeof(NewsFeedPage));
break;
case "Weather":
Frame.Navigate(typeof(WeatherPage));
break;
}
}
}
private void NavView_SelectionChanged(NavigationView sender, NavigationViewSelectionChangedEventArgs args)
{
if (args.IsSettingsSelected)
{
Frame.Navigate(typeof(SettingsPage));
}
else
{
NavigationViewItem item = args.SelectedItem as NavigationViewItem;
switch (item.Tag)
{
case "home":
Frame.Navigate(typeof(MainPage));
break;
case "attractions":
Frame.Navigate(typeof(AttractionsPage));
break;
case "placestoEat":
Frame.Navigate(typeof(PlacestoEatPage));
break;
case "map":
Frame.Navigate(typeof(BlankPage1));
break;
case "photos":
Frame.Navigate(typeof(Photos_Page));
break;
case "news":
Frame.Navigate(typeof(NewsFeedPage));
break;
case "weather":
Frame.Navigate(typeof(WeatherPage));
break;
}
}
}
private void Page_Loaded(object sender, RoutedEventArgs e)
{
}
}
}
这是MapPage C#代码,仅包含导航视图代码(如果我需要把其余的代码放在地图上特定位置的标记的代码中,让我知道不同的地图样式):
private void NavView_ItemInvoked(NavigationView sender, NavigationViewItemInvokedEventArgs args)
{
if (args.IsSettingsInvoked)
{
Frame.Navigate(typeof(SettingsPage));
}
else
{
switch (args.InvokedItem)
{
case "Home":
Frame.Navigate(typeof(MainPage));
break;
case "Attractions":
Frame.Navigate(typeof(AttractionsPage));
break;
case "Places to Eat":
Frame.Navigate(typeof(PlacestoEatPage));
break;
case "Map":
Frame.Navigate(typeof(BlankPage1));
break;
case "Photos":
Frame.Navigate(typeof(Photos_Page));
break;
case "News":
Frame.Navigate(typeof(NewsFeedPage));
break;
case "Weather":
Frame.Navigate(typeof(WeatherPage));
break;
}
}
}
private void NavView_SelectionChanged(NavigationView sender, NavigationViewSelectionChangedEventArgs args)
{
if (args.IsSettingsSelected)
{
Frame.Navigate(typeof(SettingsPage));
}
else
{
NavigationViewItem item = args.SelectedItem as NavigationViewItem;
switch (item.Tag)
{
case "home":
Frame.Navigate(typeof(MainPage));
break;
case "attractions":
Frame.Navigate(typeof(AttractionsPage));
break;
case "placestoEat":
Frame.Navigate(typeof(PlacestoEatPage));
break;
case "map":
Frame.Navigate(typeof(BlankPage1));
break;
case "photos":
Frame.Navigate(typeof(Photos_Page));
break;
case "news":
Frame.Navigate(typeof(NewsFeedPage));
break;
case "weather":
Frame.Navigate(typeof(WeatherPage));
break;
}
}
}
答案 0 :(得分:0)
浏览完我的C#代码后,我意识到我不小心从主页复制了该代码,该代码将主页设置为要访问的页面。我把它拿出来,它本身就解决了。
感谢您的帮助!