How to navigate links using a button in WPF Modern UI in C #?

I am using ModernUI . I have one problem with Button and link.

I am trying to navigate the Button Click event, and my code in "Home.xaml" is as follows

private void addGameButton_Click(object sender, RoutedEventArgs e) { BBCodeBlock bs = new BBCodeBlock(); try { bs.LinkNavigator.Navigate(new Uri("pack://application:/Pages/AddGame.xaml"), null); } catch (Exception error) { ModernDialog.ShowMessage(error.Message, FirstFloor.ModernUI.Resources.NavigationFailed, MessageBoxButton.OK); } } 

mui: Link works great in MainWindows.xaml for navigation. but I want to go to AddGame.xaml from the Home.xaml Page on the button that is on the Home.xaml page.

My file structure is below for reference.

Folder structure

So please let me know where I am doing wrong?

+6
source share
2 answers

The second parameter of the bs.LinkNavigator.Navigate method is source , which cannot be null. Try the following:

 private void addGameButton_Click(object sender, RoutedEventArgs e) { BBCodeBlock bs = new BBCodeBlock(); try { bs.LinkNavigator.Navigate(new Uri("/Pages/AddGame.xaml", UriKind.Relative), this); } catch (Exception error) { ModernDialog.ShowMessage(error.Message, FirstFloor.ModernUI.Resources.NavigationFailed, MessageBoxButton.OK); } } 
+9
source

Interestingly, the following code works in my environment:

 if (App.HasDashboardRole) { App.Current.Dispatcher.Invoke(new Action(() => { var bs = new BBCodeBlock(); bs.LinkNavigator.Navigate(new Uri("/Pages/Dashboard.xaml", UriKind.Relative), this); })); } else if (App.HasBarcodeBuilderRole) { App.Current.Dispatcher.Invoke(new Action(() => { var bs = new BBCodeBlock(); bs.LinkNavigator.Navigate(new Uri("/Pages/BarcodeBuilderPage.xaml", UriKind.Relative), this); })); } 

If this code is not:

 App.Current.Dispatcher.Invoke(new Action(() => { var bs = new BBCodeBlock(); if (App.HasDashboardRole) bs.LinkNavigator.Navigate(new Uri("/Pages/Dashboard.xaml", UriKind.Relative), this); else if (App.HasBarcodeBuilderRole) bs.LinkNavigator.Navigate(new Uri("/Pages/BarcodeBuilderPage.xaml", UriKind.Relative), this); })); 
0
source

All Articles