6

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

I am trying to navigate by Button Click event and my code in "Home.xaml" is as follow

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 fine in MainWindows.xaml for navigation. but I want to navigate to AddGame.xaml from Home.xaml Page by a Button, which is in Home.xaml page.

My file structure is as below, for reference.

Folder Structure

So please let me know, where am i doing wrong?

aloisdg
  • 22,270
  • 6
  • 85
  • 105
VarunJi
  • 685
  • 2
  • 14
  • 31
  • Look at the [documentation](http://mui.codeplex.com/wikipage?title=Link%20navigation%20with%20BBCodeBlock&referringTitle=Documentation) to make sure that Uri is correct. – Lukas Kubis Apr 01 '14 at 11:58
  • i tried many ways but not able to get the solution. even i tried stackoverflow link - [http://stackoverflow.com/questions/20031163/page-navigation-in-wpf-modern-ui] – VarunJi Apr 01 '14 at 16:39

2 Answers2

9

The second parameter of bs.LinkNavigator.Navigate method is source that cannot be null. Try this:

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);
    }
}
Lukas Kubis
  • 929
  • 5
  • 17
  • 1
    Thanks Lukas. You saved my life. And how can I activate the link as well, which is mui:Link. – VarunJi Apr 02 '14 at 12:39
  • Sorry, but I don't know what do you mean: "..how can I activate link.." – Lukas Kubis Apr 02 '14 at 13:00
  • 1
    I am using Modern UI as i mentioned in my Question. and Modern UI uses link for navigation. So i am asking about those links. like below – VarunJi Apr 02 '14 at 14:47
0

Interestingly, in my environment, the following code works:

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);
                }));
            }

When this code does 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);
                }));
J-DawG
  • 1,035
  • 9
  • 24