Howie
Howie

Reputation: 2778

Making clickable URLs in RichTextBox using bindings

My XAML has a DataTemplate defined which has ItemsSource set to some data class, which holds properties that will be presented in UI. One property is "Files", which has to display one or more files in the form of <Hyperlink NavigateUri="URLtoFILE">Filename</Hyperlink> (optional filesize).

The property is currently of type string where I'm concatenating different files' URLs and text together. But the stuff I put into that property display on screen verbatim.

I've seen this: WP8: RichTextBox has no Document property, but I have the problem of using data templates and bindings, which makes referencing the RichTextBox object in code impossible (is it?).

How can I mix text and clickable URLs within a WP8 control that is using data templates and bindings?

EDIT: If it helps, the ItemsSource always holds only one object.

EDIT: Part of XAML

<Grid>
    <phone:LongListSelector x:Name="List">
        <phone:LongListSelector.ItemTemplate>
            <DataTemplate>
                <StackPanel>
                    <RichTextBox IsReadOnly="True">
                    </RichTextBox>
                </StackPanel>
            </DataTemplate>
        </phone:LongListSelector.ItemTemplate>
    </phone:LongListSelector>
</Grid>

Upvotes: 2

Views: 260

Answers (1)

MatDev8
MatDev8

Reputation: 986

You want to show a list of urls? If you want this :

<lisbox itemSource={Binding YourItemSource} selectedItem="{Binding ItemProperty}">
 <listbox.ItemTemplate>
  <dataTemplate>
   <textblock>
    <Hyperlink Command="{Binding HyperLinkTapped}" NavigateUri="URLtoFILE"></Hyperlink>
   </textblock><
  </datatemplate>
 </listbox.itemtemplate>
</listbox>

Upvotes: 1

Related Questions