如何在MVVM绑定中使用HyperLinks将字符串转换为XAML-TextBlocks

时间:2014-09-04 09:28:15

标签: regex wpf xaml mvvm hyperlink

我正在寻找一种机制(ValueConverter?),它通过正则表达式将字符串转换为XAML,并将某些部分替换为超链接 - 类似于Wiki-MarkUp或Textile。这些字符串存储在ObservableCollection中,我正在显示VirtualizingStackPanel。

<ItemsControl x:Name="Items" ItemsSource="{Binding}">
    <ItemsControl.Template>
        <ControlTemplate>
            <ScrollViewer CanContentScroll="True">
                <ItemsPresenter/>
            </ScrollViewer>
        </ControlTemplate>
    </ItemsControl.Template>
        <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate>
            <VirtualizingStackPanel IsItemsHost="True"/>
        </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>
</ItemsControl>

举个例子:

"See [MainSection] for further instructions." 

应该成为......

<TextBlick>
    See <Hyperlink NavigateUri="{Binding Path}">
     MainSection</Hyperlink>for further instructions.
</TextBlock>

这样的事情可能吗?

考虑:

  • 这需要处理列表中的数千个条目,因此不得破坏列表虚拟化。
  • 字符串中可能有多个链接。

0 个答案:

没有答案