Binding Hyperlink to richtextblock in windows 8 Metro app

I am building a windows 8 metro app for fun/learning etc.
I have created a listview of text items that have descriptions, images etc. Inside the description, there are often hyperlinks that I would like to make clickable.

However, when binding to a textblock, xaml hyperlink code is displayed as text. Searching arround, it looks like I need to use a richtextblock for hyperlinks. I can't seem to figure out how to bind a hyperlink to it. I have found many examples from wpf showing how to extend the richtextblock using flowdocument. Flowdocument doesn't exist in the current consumer preview version of the framework.

I am reaching out to see if anyone has solved this issue or has any suggestions on what path to head down.

Edit: Code I have Currently

right now I am just binding the "text" field from my Statuses Object to a textblock binding on "text"

I have URL's in the text field which I want to be able to make clickable.

As a test I was replacing the text field of the first object with hyperlink markup

ex. feed_results[0].text = " <hyperlink .....

then trying to bind to texblock and richtextblock

Xaml

<ListView x:Name="ItemListView" ItemsSource="{Binding}"  Background="Black" Width="372" VerticalAlignment="Top" Margin="50,0,0,0">
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <StackPanel  Orientation="Vertical"  MinHeight="100">
                            <StackPanel Orientation="Horizontal">
                            <Image Source="{Binding user.profile_image_url}" Margin="0,0,15,0" VerticalAlignment="Top" />
                            <StackPanel Orientation="Vertical">
                                    <TextBlock HorizontalAlignment="Left" Foreground="Gray" Text="{Binding user.name}" FontWeight="Bold" TextWrapping="Wrap"  MaxWidth="200" />
                                    <TextBlock HorizontalAlignment="Left" Foreground="Gray"   Text="{Binding text}" TextWrapping="Wrap"  MaxWidth="200" />                      
                                </StackPanel>
                            </StackPanel>
                            <StackPanel  Margin="0,15,0,0" HorizontalAlignment="Right">
                                <TextBlock Text="{Binding created_at,  Converter={StaticResource StringConverter},ConverterParameter=Released: {0:d}}"   HorizontalAlignment="Center" Foreground="Gray" />
                            </StackPanel>
                        </StackPanel>
                    </DataTemplate>
                </ListView.ItemTemplate>

Backend Code

FeedResult<Statuses> r2 = await feed.StatusesAsync(1, 50);

            if (!r2.HasError)
            {
                feed_results = r2.Result;


                Dispatcher.Invoke(Windows.UI.Core.CoreDispatcherPriority.High, new Windows.UI.Core.InvokedHandler((o, a) =>
                {

                    ItemListView1.ItemsSource = feed_results;
                }), this, null);
            }

Microsoft removed support for inline hyperlinks from Metro XAML. You can still use HyperlinkButton for non inline hyperlinks, or if your inline hyperlinks short (1-2 words) then you could place HyperlinkButton inside of InlineUIContainer in RichTextBlock. Later solution would require some code, just using binding won't do it.

链接地址: http://www.djcxy.com/p/67378.html

上一篇: 在FlipView中格式化RichTextBlock中的文本

下一篇: 在Windows 8 Metro应用程序中将超链接绑定到richtextblock