我正在尝试创建一个超链接,用户可以单击该链接并导航到一个网站。
该链接正在运行,但我收到此异常,该异常会停止应用程序:无法将资源转换为对象。
超链接将是数据网格的一部分。这是我所拥有的:
XAML:
...
<DataTemplate x:Key="hyperlinkTemplate">
<TextBlock>
<Hyperlink NavigateUri="{Binding Link}" RequestNavigate="dataLink_RequestNavigate">
<TextBlock Text="{Binding TaskID}"></TextBlock>
</Hyperlink>
</TextBlock>
</DataTemplate>
...
<DataGrid Grid.Column="1" AutoGenerateColumns="False" ItemsSource="{Binding Tasks}" >
<DataGrid.Columns>
<DataGridTemplateColumn Header="Name width link" CellTemplate="{StaticResource hyperlinkTemplate}"></DataGridTemplateColumn>
...
==================================================== =================
后面的代码:
...
private void dataLink_RequestNavigate(object sender, System.Windows.Navigation.RequestNavigateEventArgs e)
{
Process.Start(e.Uri.ToString());
e.Handled = true;
}
...
==================================================== =================
类数据:链接
public string Link
{
get { return link; }
set
{
link = value;
Notify("Link");
}
}
==================================================== =================
任务类
[Serializable]
public class Task
{
private XmlNode node;
private string category = "";
private int taskID = -1;
private string taskName = "";
private string taskResponsible = "";
private string taskResponsibleDepartment = "";
private int priority = 5;
private string status = "Unknown";
private string predecessorIndices = "None";
private int indentLevel = 0;
private int sortOrder = 0;
private DateTime startDate = DateTime.Now;
private TimeSpan estimatedHours = default(TimeSpan);
private TimeSpan actualHours = default(TimeSpan);
private DateTime estimatedDeploymentDate = default(DateTime);
private DateTime desiredImplementationDate = default(DateTime);
private string estimatedHoursRecovery = "";
private string actualHoursRecovery = "";
private string tags = "";
private TimeSpan totalHoursActual = default(TimeSpan);
private Department iN = new Department();
private Department aPP = new Department();
private Department sIS = new Department();
private string link = "";
...
==================================================== =================
你有什么建议吗?
BR