0

我正在编写一个 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>
4

1 回答 1

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;
}
于 2012-05-26T11:27:37.887 回答