问题描述
我正在尝试创建一个超链接,用户可以单击该超链接并导航到一个网站。
I am trying to create a hypelink which the user can click and navigate to a website.
链接正在工作,但是我遇到了一个异常,该异常停止了应用程序:
无法将资源转换为对象。
The link is working but I am getting this exception which stops the application:Failed to convert resource into object.
超链接将成为数据网格的一部分。这是我所拥有的:
The hyperlink will be a part og a datagrid. Here is what I have:
...
<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
推荐答案
发现自己了。我需要将 e.handled = true;
添加到datagrid_RequestNavigate。刚刚也更新了代码示例。
Found out myself. I needed to add e.handled = true;
to the datagrid_RequestNavigate. Just updated the code examples too.
现在一切正常
这篇关于超链接不断失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!