Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WPF:超链接事件处理程序中的异常_C#_Wpf_Exception_Datagrid_Hyperlink - Fatal编程技术网

C# WPF:超链接事件处理程序中的异常

C# WPF:超链接事件处理程序中的异常,c#,wpf,exception,datagrid,hyperlink,C#,Wpf,Exception,Datagrid,Hyperlink,我有一个带有超链接列的WPF数据网格: <DataGridHyperlinkColumn Binding="{Binding DocName}"> <DataGridHyperlinkColumn.ElementStyle>` <Style> <EventSetter Event="Hyperlink.Click" Handler="DocLink_Click" /> </Style> <

我有一个带有超链接列的WPF数据网格:

<DataGridHyperlinkColumn Binding="{Binding DocName}">
  <DataGridHyperlinkColumn.ElementStyle>`
     <Style>
        <EventSetter Event="Hyperlink.Click" Handler="DocLink_Click" />
     </Style>
  </DataGridHyperlinkColumn.ElementStyle>
</DataGridHyperlinkColumn>
我能做些什么来防止这种情况

编辑

正如我所建议的,我在一个玩具应用程序中尝试了这个,它在那里起了作用。经过实验,结果表明,只有当事件发生在可导航的
页面
(而不是
窗口
)中时,才会发生这种情况。现在我们有了这个:

App.xaml:

<Application x:Class="WpfApplication1.App"
   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
   StartupUri="NavWin.xaml">
</Application>

您是否在应用程序之外尝试过此功能?我不认为这种情况下会失败,我想问题不在你的代码中provide@ArsenMkrt-我对问题进行了编辑,以显示我的发现。
<Application x:Class="WpfApplication1.App"
   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
   StartupUri="NavWin.xaml">
</Application>
<NavigationWindow x:Class="WpfApplication1.Container"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  Title="NavTest" 
  Source="MainPage.xaml">
</NavigationWindow>
<Page x:Class="WpfApplication1.MainPage"
   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:local="clr-namespace:WpfApplication1"
  Title="MainPage" Height="350" Width="525">

  <Grid>
    <DataGrid x:Name="grid" ItemsSource="{Binding Items}" AutoGenerateColumns="False" >
      <DataGrid.Columns>
        <DataGridHyperlinkColumn Binding="{Binding Name}" Header="Name">
           <DataGridHyperlinkColumn.ElementStyle>
              <Style>
                 <EventSetter Event="Hyperlink.Click" Handler="ItemLink_Click" />
              </Style>
           </DataGridHyperlinkColumn.ElementStyle>
        </DataGridHyperlinkColumn>
      </DataGrid.Columns>
    </DataGrid>
  </Grid>
</Page>
public partial class MainPage : Page
{
  ... 
  private void ItemLink_Click(object sender, RoutedEventArgs e)
  {
     MessageBox.Show("Crash");
  }
}