Wpf 超链接列表框赢得';t将单击的超链接显示为选定项或当前项
我的一个网格单元中有一个带有超链接的列表框。当我单击列表框中的任何项目时,当前项目始终是列表框中的第一条记录,所选项目始终为空。这是我的WPF。我做错了什么Wpf 超链接列表框赢得';t将单击的超链接显示为选定项或当前项,wpf,xaml,listbox,Wpf,Xaml,Listbox,我的一个网格单元中有一个带有超链接的列表框。当我单击列表框中的任何项目时,当前项目始终是列表框中的第一条记录,所选项目始终为空。这是我的WPF。我做错了什么 <DataTemplate x:Key="CellTemplate.InputManagersList"> <StackPanel Orientation="Horizontal"> <ListBox ItemsSource="{Binding Path=InputMa
<DataTemplate x:Key="CellTemplate.InputManagersList">
<StackPanel Orientation="Horizontal">
<ListBox ItemsSource="{Binding Path=InputManagers}" HorizontalAlignment="Left">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock>
<Hyperlink Name="inputManagerName"
Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=DataContext.OpenInputManagerViewCommand}"
CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBox}}}">
<TextBlock Text="{Binding Path=Name}" />
</Hyperlink>
</TextBlock>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
<ListBox.Style>
<Style TargetType="ListBox">
<Setter Property="HorizontalAlignment" Value="Left"/>
<Setter Property="BorderThickness" Value="0"/>
</Style>
</ListBox.Style>
</ListBox>
</StackPanel>
</DataTemplate>
请在列表视图对象中绑定SelectedItem=“{Binding SelectedName}”
。您如何知道所选的项目?列表框甚至没有名称。请将代码发布到选中项的位置。我的命令方法的参数是一个列表框。所以我只看代码中的对象。listBox.SelectedItem;所以你不打算发布那个代码?我不确定你想要什么代码。C代码非常简单。我检查了我的方法参数,从上面的xaml中可以看到,它是列表框本身。然后我选中列表框。选择编辑项。它是空的。这是C#代码的总和。这确认了您不会在获得空引用的地方发布代码。但问题是关于空引用。没有一个被接受的答案,用Xaml?在我上面的xaml中,它会去哪里?