为了点击链接,我们使用
<DataGrid x:Name="data" LoadingRow="load" ItemsSource="{Binding Path=pull_gmc,Mode=TwoWay}" CanUserDeleteRows="True" AutoGenerateColumns="False" CanUserSortColumns="True">
<DataGrid.Columns >
<DataGridHyperlinkColumn Header="产品链接" ContentBinding="{Binding Path=prond}" Binding="{Binding Path=productId}">
<DataGridHyperlinkColumn.ElementStyle>
<Style TargetType="TextBlock">
<EventSetter Event="Hyperlink.Click" HandledEventsToo="False" Handler="url"></EventSetter>
<!--<EventSetter Event="MouseLeftButtonDown" Handler="url"></EventSetter>-->
</Style>
</DataGridHyperlinkColumn.ElementStyle>
</DataGridHyperlinkColumn>
</DataGrid.Columns>
</DataGrid>
public class gmccolleague
{
public gmccolleague()
{
}
/// <summary>
/// 产品链接
/// </summary>
public string productId
{
set;
get;
}
public static string prond
{
set;
get;
} = "产品链接";
public int total
{
set;
get;
}
/// <summary>
/// 关键字
/// </summary>
public string primary
{
set;
get;
}
/// <summary>
/// 标题
/// </summary>
public string title
{
set;
get;
}
/// <summary>
/// 产品类别
/// </summary>
public string leaf_cat_name
{
set;
get;
}
/// <summary>
/// 使用次数
/// </summary>
public int count
{
set;
get;
}
/// <summary>
/// 质量得分
/// </summary>
public string iq_score
{
set;
get;
}
}
public ObservableCollection<gmccolleague> pull_gmc
{
set;
get;
} = new ObservableCollection<gmccolleague>();
private void url(object sender, RoutedEventArgs e)
{
try
{
Uri destination = ((Hyperlink)e.OriginalSource).NavigateUri;
Process.Start("http://" + destination.ToString());
}
catch
{
}
}