我有ListView和GridViewColumn
<GridViewColumn Header="Name">
<GridViewColumn.CellTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal"
MouseEnter="StackPanel_MouseEnter">
<CheckBox Checked="CheckBox_Checked"
Unchecked="CheckBox_Unchecked">
<CheckBox.IsChecked>
<Binding Path="IsSelected" RelativeSource="{RelativeSource AncestorType={x:Type ListViewItem}}"/>
</CheckBox.IsChecked>
</CheckBox>
<TextBlock x:Name="textBlock"
Text="{Binding Name}"/>
</StackPanel>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>因此,如您所见,我添加了StackPanel MouseEnter事件:
private void StackPanel_MouseEnter(object sender, MouseEventArgs e)
{
}因此,我的问题是在这个StackPanel_MouseEnter函数中:如何获得GridViewColumn中的当前对象?(甚至是我的ListView中的当前索引)
发布于 2017-10-26 09:41:37
通过访问堆栈面板的Name,您可以获得该行绑定到的当前项(例如绑定TextBlock的项):
private void StackPanel_MouseEnter(object sender, MouseEventArgs e) {
var item = ((FrameworkElement)sender).DataContext as YourItem;
if (item != null) {
// do stuff
}
}https://stackoverflow.com/questions/46950574
复制相似问题