This is a migrated thread and some comments may be shown as answers.

Hyperlink click

3 Answers 184 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
CarlosLima
Top achievements
Rank 1
CarlosLima asked on 17 Nov 2010, 06:43 PM
I've read on a post from October that the Beta version of Q3 had something like hyperlinkclicked events.

I've downloaded the latest version of Q3 (2010.3.1110.1040) and I've created this on the xaml:

xmlns:t="clr-namespace:Telerik.Windows.Documents.Model;assembly=Telerik.Windows.Documents"

 

<telerik:RadRichTextBox x:Name="rtBox" Height="293" Background="LightGray">
              <telerik:RadRichTextBox.Document>
                  <telerik:RadDocument DefaultPageLayoutSettings="816,1056" LayoutMode="Paged" PageViewMargin="10,10" ParagraphDefaultSpacingAfter="10" SectionDefaultPageMargin="95,95,95,95">
                      <t:Section PageMargin="96,96,96,96">
                          <t:Paragraph SpacingAfter="6.66666650772095" SpacingBefore="6.66666650772095">
                                  <t:Span FontFamily="Calibri" FontWeight="Bold" Text="Title." />
                          </t:Paragraph>
                          <t:Paragraph SpacingAfter="6.66666650772095" SpacingBefore="6.66666650772095">
                              <t:Span FontFamily="Calibri" Text="text text text" />
                              <t:Hyperlink x:Name="atribute1" FontFamily="Verdana" HighlightColor="#FF9BBB59" Target="Self" Text="...." UnderlineDecoration="Line" URL="" />
                                  <t:Span FontFamily="Calibri" Text=" % (" />
                                  <t:Hyperlink x:Name="atribute2" FontFamily="Verdana" HighlightColor="#FF9BBB59" Target="Self" Text="....." UnderlineDecoration="Line" URL="" />
                                  <t:Span FontFamily="Calibri" Text=") text text text." />
                          </t:Paragraph>
                          <t:Paragraph SpacingAfter="6.66666650772095" SpacingBefore="6.66666650772095" />
                      </t:Section>
                  </telerik:RadDocument>
              </telerik:RadRichTextBox.Document>
          </telerik:RadRichTextBox>

 

 

 

but I don't have any other property for Hyperlink clicks....


What we need to do is have some sort of text (like a contract document for example) where there are areas to be filled by the user. The document will be readonly but the user clicks those areas (hyperlinks initially) and that shoud have an event on the c# that will popup something for input and then will replace the document hyperlink with that text..

I've also tried with a button but I read that it coudn't be serialized.. since the document will be returned by the database through a service I'm not sure it would be a good choice. Besides that, the style of the button would also need a lot of changing to make it more "in line text like".

Thanks

3 Answers, 1 is accepted

Sort by
0
Iva Toteva
Telerik team
answered on 18 Nov 2010, 05:07 PM
Hi carlos,

HyperlinkClicked is an event of RadRichTextBox and not Hyperlink itself.

You can declare a handler for it it like this:

<telerik:RadRichTextBox x:Name="rtBox" Height="293" Background="LightGray" HyperlinkClicked="rtBox_HyperlinkClicked">

Then, in code-behind you can handle the event as you please:
private void rtBox_HyperlinkClicked(object sender, Telerik.Windows.Documents.Model.HyperlinkClickedEventArgs e)
{
    Hyperlink link = sender as Telerik.Windows.Documents.Model.Hyperlink;
    MessageBox.Show(link.URL);
    e.Handled = true; // if you want to suppress the default behavior (opening the URL in the browser)
}

Please, note that if you do not assign a URL to the Hyperlink, the event will not be fired when clicking on the hyperlink.

If you need further assistance, do not hesitate to contact us again.

Best wishes,
Iva
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
0
CarlosLima
Top achievements
Rank 1
answered on 18 Nov 2010, 07:11 PM
I managed to find another solution for others who may need it.

First I use an inlineUIContainer with a common Hyperlinkbutton inside it (xaml below):

<t:RadDocument xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:t="clr-namespace:Telerik.Windows.Documents.Model;assembly=Telerik.Windows.Documents" version="1.0" DefaultPageLayoutSettings="816,1056" LayoutMode="Paged" PageViewMargin="10,10" ParagraphDefaultSpacingAfter="10" SectionDefaultPageMargin="95,95,95,95">
  <t:Section PageMargin="96,96,96,96">
    <t:Paragraph SpacingAfter="6.66666650772095" SpacingBefore="6.66666650772095">
      <t:Span FontFamily="Calibri" FontWeight="Bold" Text="title." />
    </t:Paragraph>
    <t:Paragraph SpacingAfter="6.66666650772095" SpacingBefore="6.66666650772095">
      <t:Span FontFamily="Calibri" Text="text text text " />
<telerik:InlineUIContainer xmlns="http://schemas.microsoft.com/client/2007" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Height="14" Style="{x:Null}" Width="33" xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation">
  <telerik:InlineUIContainer.DefaultStyleSettings>
    <Telerik_Windows_Documents_Model_Styles_Telerik_Windows_Documents:StyleDefinition BasedOn="{x:Null}" xmlns:Telerik_Windows_Documents_Model_Styles_Telerik_Windows_Documents="clr-namespace:Telerik.Windows.Documents.Model.Styles;assembly=Telerik.Windows.Documents" />
  </telerik:InlineUIContainer.DefaultStyleSettings>
  <HyperlinkButton Content="link" FontSize="12" Margin="0,0,0,0" Tag="25|xxxx" VerticalAlignment="Bottom">
    <HyperlinkButton.Background>
      <SolidColorBrush Color="#00FFFFFF" />
    </HyperlinkButton.Background>
    <HyperlinkButton.Foreground>
      <SolidColorBrush Color="#FFFF0000" />
    </HyperlinkButton.Foreground>
  </HyperlinkButton>
</telerik:InlineUIContainer>
<t:Span FontFamily="Calibri" Text=" % (" /><t:Span FontFamily="Calibri" Text=") text text" /></t:Paragraph>
    <t:Paragraph SpacingAfter="6.66666650772095" SpacingBefore="6.66666650772095" />
  </t:Section>
</t:RadDocument>



Second, after loading the document I define the click events for the hyperlinks:
private void CreateHyperlinkEventClicks()
        {
            List<Telerik.Windows.Documents.Model.InlineUIContainer> links = Editor.Document.EnumerateChildrenOfType<Telerik.Windows.Documents.Model.InlineUIContainer>().ToList();
            foreach (Telerik.Windows.Documents.Model.InlineUIContainer container in links)
            {
                HyperlinkButton btn = (HyperlinkButton)container.UiElement;
                btn.Click += new RoutedEventHandler(btn_Click);
            }
        }

void btn_Click(object sender, RoutedEventArgs e)
        {

HyperlinkButton btnSender = (HyperlinkButton)sender;
//do something
}


Thanks anyway.
A suggestion for next releases of the richtextbox, have some paragraphs editable and others not (property) if the richtextbox isreadonly = true;

Carlos
0
Iva Toteva
Telerik team
answered on 22 Nov 2010, 09:01 AM
Hello carlos,

Thank you for sharing your approach.
As for your suggestion, we have reviewed this type of functionality but haven't scheduled it for a specific release yet.

Kind regards,
Iva
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
Tags
RichTextBox
Asked by
CarlosLima
Top achievements
Rank 1
Answers by
Iva Toteva
Telerik team
CarlosLima
Top achievements
Rank 1
Share this question
or