【发布时间】:2014-05-25 09:09:13
【问题描述】:
我又有问题了。我的问题是 我不知道如何在 XML 文件中存储超链接以及如何将其从那里检索到 WPF ListBox。在我的应用程序中,我按以下方式编写 XML 文件:
<?xml version="1.0" encoding="utf-8" ?>
<Books xmlns="">
<Category name="Computer Programming">
<Book>
<Author>H. Schildt</Author>
<Title>C# 4.0 The Complete Reference</Title>
<!--This is a hyperlink description-->
<Link>https://www.mcgraw-hill.co.uk/html/007174116X.html</Link>
</Book>
</Category>
</Books>
在窗口资源部分的 XAML 中,我以以下方式编写:
<Window.Resources>
. . . . . . . . . .
<DataTemplate x:Key="detailDataTemplate">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding XPath=Title}"/>
<TextBlock Text="{Binding XPath=Author}"/>
<TextBlock Text="{Binding XPath=Link}"/>
</StackPanel>
</DataTemplate>
. . . . . . . . . . .
</Window.Resources>
最后我在 ListBox 标记中写道:
<ListBox Name="lbxBooks" Grid.Row="1" Grid.Column="0"
. . . . . . . . . .
ItemTemplate="{StaticResource detailDataTemplate}"
IsSynchronizedWithCurrentItem="True"/>
但在应用程序启动后,超链接在屏幕上显示为简单字符串,该字符串未启用且不允许鼠标单击以获取互联网资源。所以它不能作为互联网资源的参考正常工作。它显示为简单的文本字符串。 如何更正此错误并强制链接正常工作?我必须在 XML 文件和 XAML 中更正什么?非常感谢您的帮助。
【问题讨论】: