zoukankan      html  css  js  c++  java
  • WPF ListView和ListBox等双击事件问题

    上两篇文章中说双击行获取不到当前数据对象问题,

    http://www.cnblogs.com/ligl/p/5636899.html

    http://www.cnblogs.com/ligl/p/5629802.html

    后来又研究发现可以从MouseButtonEventArgs参数中获取到

      <ListBox Grid.Row="1" ItemsSource="{Binding DataList}" 
                     MouseDoubleClick="ListBox_MouseDoubleClick"
                     SelectedItem="{Binding CurrentSelectItem}" Background="AliceBlue">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <DockPanel Height="50"  Background="DarkGray" Width="300">
                            <TextBox Text="{Binding Name}"  Height="30" Width="200" Background="DimGray"></TextBox>
                        </DockPanel>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
    View Code
     private void ListBox_MouseDoubleClick(object sender, MouseButtonEventArgs e)
            {
                var txtBox = e.Device.Target as TextBox;
                var model=txtBox.DataContext as ListBoxModel;
                ListBox listBox = sender as ListBox;
                if (listBox == null || listBox.SelectedItem == null)
                {
                    MessageBox.Show("ListBox1双击对象为空...");
                }
            }
    View Code

    主要Code如下

      private void ListBox_MouseDoubleClick(object sender, MouseButtonEventArgs e){
    var txtBox = e.Device.Target as TextBox; var model=txtBox.DataContext as ListBoxModel;//ListBoxModel是自定义的数据对象
    }
  • 相关阅读:
    (转)详谈高端内存和低端内存
    高级声明------定义一个函数指针数组指针
    A Bug's Life POJ
    How Many Answers Are Wrong HDU
    A
    B
    数据处理----离散化
    Serval and Parenthesis Sequence CodeForces
    D
    C
  • 原文地址:https://www.cnblogs.com/ligl/p/5639415.html
Copyright © 2011-2022 走看看