积极答复者
WPF 如何在触摸Touch事件里模拟双击

问题
答案
-
你好 !
我是这样写的
int selectIndex = 0;
private void ListViewContent_TouchDown(object sender, TouchEventArgs e)
{
//MessageBox.Show("Time: " + e.Timestamp);
ListBox ls = sender as ListBox;
selectIndex = ls.SelectedIndex;
Device lsItem = ls.SelectedItem as Device;
if (lsItem == null) return;
//1、实例化弹出窗
DevDetaillControl ddc = new DevDetaillControl(lsItem);
ddc.Closed += new EventHandler(ddc_Closed);
ddc.ShowDialog();
}
void ddc_Closed(object sender, EventArgs e)
{
this.ListViewContent.SelectedIndex = selectIndex;
}这样是可以,关闭弹出窗体的时候能将ListViewContent 的Item选中,但是ListViewContent这个控件就是无法获取焦点,我再次点击的时候才能获取。
- 已标记为答案 weiss_2009 2014年8月12日 2:49
- 取消答案标记 weiss_2009 2014年8月12日 2:49
- 已标记为答案 weiss_2009 2014年8月12日 2:49
全部回复
-
你好。
Touch事件可以这样处理:
首先为控件添加TouchDown事件,然后进行处理
int lastTouchTimestamp = 0; private void Grid_TouchDown(object sender, TouchEventArgs e) { if (e.Timestamp - lastTouchTimestamp < 300) { // 添加双击处理程序 lastTouchTimestamp = 0; } else { lastTouchTimestamp = e.Timestamp; } }
上面代码中,我们设定两次点击间隔为0.3秒内,就认定为双击。你也可以根据你测试的效果进行调整。
希望我的答案能帮助更多的人。 博客:http://shaomeng.cnblogs.com/
- 已编辑 shao.meng 2014年8月11日 6:41
- 已建议为答案 Franklin ChenMicrosoft employee, Moderator 2014年8月12日 2:15
-
你好 !
我是这样写的
int selectIndex = 0;
private void ListViewContent_TouchDown(object sender, TouchEventArgs e)
{
//MessageBox.Show("Time: " + e.Timestamp);
ListBox ls = sender as ListBox;
selectIndex = ls.SelectedIndex;
Device lsItem = ls.SelectedItem as Device;
if (lsItem == null) return;
//1、实例化弹出窗
DevDetaillControl ddc = new DevDetaillControl(lsItem);
ddc.Closed += new EventHandler(ddc_Closed);
ddc.ShowDialog();
}
void ddc_Closed(object sender, EventArgs e)
{
this.ListViewContent.SelectedIndex = selectIndex;
}这样是可以,关闭弹出窗体的时候能将ListViewContent 的Item选中,但是ListViewContent这个控件就是无法获取焦点,我再次点击的时候才能获取。
- 已标记为答案 weiss_2009 2014年8月12日 2:49
- 取消答案标记 weiss_2009 2014年8月12日 2:49
- 已标记为答案 weiss_2009 2014年8月12日 2:49
-
你好!我这样也试过了,还是不能获取焦点,只要弹出窗口后,关闭弹出窗口就没有焦点了。
你好,
因为您的原问题已经解决,为了论坛更好地讨论,建议您开新帖,谢谢理解:)
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.- 已编辑 Franklin ChenMicrosoft employee, Moderator 2014年8月12日 2:17