Need help setting up NavigateUri property of an Hyperlink instance

The following code throws an exception:

Hyperlink link = new Hyperlink();
link.NavigateUri = new Uri("Page2.xaml");

because it can't convert
"Page2.xaml" - which is part of the project - to a Uri.


But it's confusing because the following XAML works:

<Hyperlink NavigateUri="Page2.xaml">Here</Hyperlink>

What kind of magic is the XAML compiler doing And how can I acomplish the same in C#





Answer this question

Need help setting up NavigateUri property of an Hyperlink instance

  • Brian Laws

    You might want to try

    new Uri("Page2.xaml",UriKind.RelativeOrAbsolute);


  • rmicro1

    Thanks a lot!

    Aditionally, is it possible to pass a parameter to "Page2.xaml" I am wondering if I could do something like this:

    new Uri("Page2 p=test", UriKind.RelativeOrAbsolute);

    And if it's possible, how the class, which is inheriting from Page, would access that parameter


  • Need help setting up NavigateUri property of an Hyperlink instance