/// <summary> /// 当鼠标双击某个学员查看这个学员的详细信息 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void smDgStudentLsit_MouseDoubleClick(object sender, MouseButtonEventArgs e) { //接收查看是什么双击进入 //object o = sender; //SelectedItem选中单个元素选中第一项,如果有多个也会只选第一个;SelectedItems选中多个元素 //如果StudentsExt转成这个类型,表示我们点击时的这一行数据是StudentsExt这个类型 StudentsExt ext = smDgStudentLsit.SelectedItem as StudentsExt;//只能现在只能双击不能拿到学员的信息 //判断点击这个按钮是否为空,就是没点击到这行数据,这行没数据,如为空返回 if (ext == null) { return; } #region//对以下代码解释 /*//1.如何拿到学员的ID,通过ID拿到整行数据 * //2.ext要通过这个点击查询到所有学生ID,为什么ext可以点出StudentId,原因是Binding StudentId的绑定来获取的 * //3.双击后把ext.StudentId获取到的ID带入sm中GetDoubleStudentsExt的这个方法 * //4.如何把DoubleStu传递进WindowDoubleStu这个窗口里面,通过WindowDoubleStu窗口中函数的参数 * //5.老师:(1)当这个学员的完整信息已经存在的话,证明已经打开了一个窗口;(2)除非是打开新的学员窗口,否则只能把之前的窗口呈现出来 * StudentsExt DoubleStu = sm.GetDoubleStudentsExt(ext.StudentId); * * //如何展示用户信息 * View.WindowDoubleStu WindowdoubleStu = new WindowDoubleStu(DoubleStu);//这样就把含有某一个学生ID的全部值拿到了 * //Show可以打开多个窗口;ShowDialog不能同时打开多个窗口 * WindowdoubleStu.Show();*/ #endregion //list有一个属性判断list确定某元素是否存在 //DoubleList只存放学生ID if (DoubleList.Contains(ext.StudentId))//存在 { foreach (WindowDoubleStu item in WindowDouStu) {//遍历WindowDoubleStu窗口的数据 //item表示把WindowDoubleStu这个窗口的Stuext数据拿到了,当被触发时两个数据一样,表示已经打开了窗口,然后进入if判断让其item(表示整个窗口)在激活的状态下 if (item.Stuext == ext.StudentId) { //只能激活窗口,不能创建多个窗口 item.Activate(); } } } else//不存在,下面的窗口没关,上面的作判断 { StudentsExt DoubleStu = sm.GetDoubleStudentsExt(ext.StudentId);//给DoubleStu赋值 //(1)然后把DoubleList里面的属性改成int,(2)然后在DoubleStu把学生ID添加名字为DoubleList的list DoubleList.Add(DoubleStu.StudentId); View.WindowDoubleStu WindowdoubleStu = new WindowDoubleStu(DoubleStu);//实例化窗口并传入学生数据 //问题再次双击关闭窗口学生的行就点不出来,原因是DoubleList;里面已经有一个学生id了,所以再次双击就出不来了;所以我们要关闭的时候在把他对应的数据移除掉 WindowdoubleStu.Closed += WindowdoubleStu_Closed; WindowDouStu.Add(WindowdoubleStu);//用list把窗口装起来了 WindowdoubleStu.Show(); } }