0
我試圖創建一個用戶可以點擊並導航到網站的超鏈接。超鏈接不斷失敗
該鏈接正在工作,但我得到這個異常,它停止應用程序: 無法將資源轉換爲對象。
超鏈接將成爲數據網格的一部分。以下是我有:
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;
}
...
= ================================================== ===============
上一級數據:Link
public string Link
{
get { return link; }
set
{
link = value;
Notify("Link");
}
}
=========================================== =======================
Task類
[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
你爲什麼要同時使用'NavigateUri'財產和'RequestNavigate'事件?前者不夠嗎? –
你可以粘貼任務集合的代碼及其類型嗎? –
爲什麼?是因爲我遵循了這個問題的答案:http://stackoverflow.com/questions/2092890/add-hyperlink-to-textblock-wpf你有什麼建議? – Sulby