Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
See more:
Hi,
What is the easiest way to make a hyperlink reference a relativeURI?
I've got the following code, but it expects a full URI so it doesn't work as I would like it (but works according to the specification on MSDN).
XML
<RichTextBox  IsReadOnly="True">
  <Paragraph>
    <Run>Please </Run>
    <Hyperlink 
       NavigateUri="/Books/Chapters/Page" 
       TargetName="ContentFrame"> 
       click here 
    </Hyperlink>
    <Run> to see more</Run>
  </Paragraph>
</RichTextBox>

I've had a look at a few articles:
Creating-Actionlinks-in-a-Silverlight-RichTextBox
[^]
Using-RichTextBox-in-Silverlight-4[^]
but just wondered if anyone had a simple trick to do this.
Best regards
Erik
Posted

Okay I knew I didn't put all that work into a solution for nothing. See this answer...href tag error running on server[^]
 
Share this answer
 
Comments
Erik Rude 2-Jul-12 3:52am    
Thanks, I'll just have a play around and see if this fixes the issue (Can't see why not, but I'll check and then come back and mark it solved). Cheers
Erik
Erik Rude 3-Jul-12 6:05am    
Hmm, I've tested this with the RichTextBox Hyperlink in my solution and it still doesn't play ball. The message I get is

Microsoft JScript runtime error: Unhandled Error in Silverlight Application

Code: 4004 Category: ManagedRuntimeError

Message: System.InvalidOperationException: No XAML was found at the location '/Books/Books/Chapters/Page.xaml'.

at System.Windows.Navigation.PageResourceContentLoader.EndLoad(IAsyncResult asyncResult)...

This would be because the RtfTextBox in on a Page sitting in a navigation:Frame with a UriMapping like this:

urimapper:urimapping mappeduri="/Books/{pageName}.xaml" uri="/{pageName}",

but if I change the xaml to this I still get the error

targetname="ContentFrame" navigateuri="/Chapters/Page">

but this time it reports

Message: System.InvalidOperationException: No XAML was found at the location '/Books/Chapters/Page.xaml'.

And the /Books/Chapters/Page.xaml does exist in the root of my site.
Erik Rude 25-Jul-12 5:07am    
This wasn't quite the answer, but very useful info none the less. I'll mark it as a solution. CHeers
Erik
I didn't manage to get this to work properly, so instead I just went with the quick and dirty workaround:
XML
<richtextbox isreadonly="True">
  <paragraph>
    <run>Please </run>
      <hyperlink click="Hyperlink_Click"> click here </hyperlink>
    <run> to see more</run>
  </paragraph>
</richtextbox>

And then navigate in the HyperLink_Click event

C#
private void Hyperlink_Click(object sender, RoutedEventArgs e)
{
  TargetName="ContentFrame"
  var uri = new Uri("/Chapters/Pages", UriKind.Relative);
  NavigationService.Navigate(uri);
}
 
Share this answer
 
Comments
Sandeep Mewara 25-Jul-12 5:20am    
5 for coming back and reporting update on your issue with how you handled it.
Nathan Stiles 28-Jul-12 0:02am    
True +5
Erik Rude 30-Jul-12 7:26am    
Thanks - I do find some very good hints in the Questions sections - when they have been answered and marked as such. Cheers.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900