当前位置:   article > 正文

【WPF】ListView控件双击事件,获取双击行的信息_wpf listview 双击

wpf listview 双击

我有一个ListView列表,我要实现双击某一行展开详细页,前台代码如下:其中MouseDoubleClick="myplaneLV_MouseDoubleClick"是双击事件,myplaneLV_MouseDoubleClick对应后台代码。

<ListView Margin="0,30,0,0" x:Name="myplaneLV" ScrollViewer.VerticalScrollBarVisibility="Hidden" ScrollViewer.HorizontalScrollBarVisibility="Hidden"   MouseDoubleClick="myplaneLV_MouseDoubleClick">
            <ListView.Resources>
              <!--  <Style TargetType="GridViewColumnHeader">
                    <Setter Property="Visibility" Value="Collapsed"></Setter>
                </Style>-->
                
            </ListView.Resources>
            
            <ListView.View>
                <GridView>
                    <GridViewColumn Header="选择">
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <CheckBox Content="" Click="CheckBox_Click" Tag="{Binding rowid}"/>
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                    <GridViewColumn Header="计划工作" Width="550">
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock TextWrapping="Wrap" Text="{Binding PlanInfo}"></TextBlock>
                            </DataTemplate>
                            
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                    <GridViewColumn  Header="创建时间" DisplayMemberBinding="{Binding Path=CreateTime,StringFormat='{}{0:yyyy年MM月dd日}',ConverterCulture=zh-CN}"/>
                    <GridViewColumn  Header="计划完成时间" DisplayMemberBinding="{Binding Path=Plane,StringFormat='{}{0:yyyy年MM月dd日}',ConverterCulture=zh-CN}"/>
                </GridView>                
            </ListView.View>
        </ListView>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30

myplaneLV_MouseDoubleClick双击事件对应代码如下:

private void myplaneLV_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            DataRowView rowView = myplaneLV.SelectedItem as DataRowView;
            MessageBox.Show(rowView[1].ToString());
           // DataRowView rowv = (DataRowView)myplaneLV.SelectedItem;
          //  MessageBox.Show(myplaneLV.SelectedItem.GetType().ToString());
        }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

最终效果如下图:
在这里插入图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/凡人多烦事01/article/detail/537717
推荐阅读
相关标签
  

闽ICP备14008679号