一直在搞乱这个,似乎无法搞清楚。似乎对象发送者实际上是ListView ..所以即使我弄清楚如何将GridViewColumn作为一个孩子...我不知道如何区分实际点击了哪个列?
<ListView x:Name="SingleTweet_ListView"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
MouseLeftButtonUp="SingleTweet_ListView_MouseLeftButtonUp"
Height="200" Margin="5,5,5,5" FontSize="12"
GridViewColumnHeader.Click="GridViewColumnHeaderClickedHandler">
<ListView.View>
<GridView>
<GridViewColumn Header="Screen Name"
DisplayMemberBinding="{Binding Col1}" Width="112"/>
<GridViewColumn Header="Tweet"
DisplayMemberBinding="{Binding Col2}" Width="623"/>
</GridView>
</ListView.View>
</ListView>
void GridViewColumnHeaderClickedHandler(object sender, RoutedEventArgs e)
{
MessageBox.Show(((GridViewColumn)sender).Header.ToString());
//error cus the sender is actually the listview?
}
答案 0 :(得分:2)
发件人将为ListView
,但您可以检查OriginalSource
GridViewColumnHeader
,并且可以从中获取列:
MessageBox.Show(((GridViewColumnHeader)e.OriginalSource).Column
.Header.ToString());