DataGrid中的超链接无法正常工作

时间:2012-05-26 11:09:40

标签: c# wpf

我正在编写一个WPF应用程序,在一个用户控件中,我在DataGrid中使用了一个超链接,但它无法正常工作。我正在使用bing.com进行测试。

<DataGrid Grid.Row="1" 
  AutoGenerateColumns="False" 
  Height="Auto" 
  Name="dataGrid1" 
  Width="Auto" 
  CanUserAddRows="False" 
  CanUserResizeColumns="True" 
  HorizontalAlignment="Stretch" 
  VerticalAlignment="Stretch" 
  Focusable="True" 
  IsHitTestVisible="False" 
  BorderThickness="0">
    <DataGrid.Columns >
        <DataGridTextColumn Header="Start Time" Width="*" Binding="{Binding Path=startTime}" CanUserSort="True"/>
        <DataGridTextColumn Header="End Time"   Width="*" Binding="{Binding Path=endTime}" CanUserSort="True"/>
        <DataGridTextColumn Header="Resources"  Width="*" Binding="{Binding Path=resources}" CanUserSort="True"/>
        <DataGridTextColumn Header="Action"  Width="*" Binding="{Binding Path=action}" CanUserSort="True"/>
        <DataGridTextColumn Header="Result"  Width="*" Binding="{Binding Path=result}" CanUserSort="True"/>
        <DataGridTemplateColumn Header="Health"  Width="*" CanUserSort="True">
            <DataGridTemplateColumn.CellTemplate>
                <DataTemplate>
                    <TextBlock >
                        <Hyperlink NavigateUri="http://www.bing.com" RequestNavigate="Hyperlink_RequestNavigate"><!--"{Binding Path=healthUri}">-->
                            <TextBlock Text="{Binding Path=healthUri}" Focusable="True" />                                                                                    
                        </Hyperlink>                                    
                    </TextBlock>
                </DataTemplate>
            </DataGridTemplateColumn.CellTemplate>
        </DataGridTemplateColumn>
    </DataGrid.Columns>
</DataGrid>

1 个答案:

答案 0 :(得分:1)

来自MSDN:

超链接导航只有在超链接的直接或间接父级是导航主机时才会发生,包括NavigationWindow,Frame或任何可以托管XBAP的浏览器(包括Internet Explorer 7,Microsoft Internet Explorer 6和Firefox 2.0) +)。

你可以这样做:

<Hyperlink NavigateUri="http://www.bing.com" RequestNavigate="Hyperlink_RequestNavigate">

private void Hyperlink_RequestNavigate(object sender, RequestNavigateEventArgs e)
{
    Process.Start(new ProcessStartInfo(e.Uri.AbsoluteUri));
    e.Handled = true;
}