WPF ListViewItem事件未在触摸屏上正常触发 [英] WPF ListViewItem events not firing properly on Touchscreen

查看:62
本文介绍了WPF ListViewItem事件未在触摸屏上正常触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 

 

<Window x:Class="WpfApplication2.MainWindow"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         WindowState="Maximized"
         Title="MainWindow" Height="550" Width="525">
     <Grid>
         <Grid.RowDefinitions>
             <RowDefinition/>
             <RowDefinition Height="4*"/>
             <RowDefinition/>
         </Grid.RowDefinitions>
         <TextBox Name="TextBox" VerticalContentAlignment="Center" FontSize="30" ></TextBox>
         <ListView Grid.ColumnSpan="6"  Grid.Row="1"
                      x:Name="GridControlProducts"
                     SelectionMode="Single"
                     ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                     ScrollViewer.VerticalScrollBarVisibility="Disabled">
             <ListView.ItemsPanel>
                 <ItemsPanelTemplate>
                     <WrapPanel Orientation="Horizontal" />
                 </ItemsPanelTemplate>
             </ListView.ItemsPanel>
             <ListView.ItemContainerStyle>
                 <Style TargetType="{x:Type ListViewItem}">
                     <Setter Property="Width" Value="200"/>
                     <Setter Property="Height" Value="200"/>
                     <EventSetter Event="PreviewMouseDown" Handler="button_Click" />
                 </Style>
             </ListView.ItemContainerStyle>
         </ListView>       


         <Button Content="Close" Grid.Column="0" Grid.Row="2" Click="Button_Click_1" ></Button>

     </Grid>
</Window>

//代码落后于

// code behind

public MainWindow()
         {
             InitializeComponent();

             for (int i = 0; i < 10; i++)
             {
                 this.GridControlProducts.Items.Add("Test");
             }
         } 


 private int c = 1;
         private void button_Click(object sender, RoutedEventArgs e)
         {
             this.TextBox.Text = this.c++.ToString();
         }



我有一个WPF触摸屏应用程序,其中包含列表视图模板中的产品列表。 



使用鼠标,一切都按预期工作。但是,在触摸屏上,触摸事件不会每次都触发。例如,如果我连续按下列表视图中的10个按钮,则可能会注册7个触摸,3个触摸则不会。



如果我触摸标准按钮就它本身而言,它非常敏感。我的模板中的按钮不是(非常命中和错过)。


I have a WPF touchscreen application which contains a list of products in a list view template. 

Using a mouse everything works as you would expect. However, on a touchscreen the touch events don't fire every time. For example, if I press 10 buttons in my list view in a row, maybe 7 touches will register and 3 touches won't.

If I touch a standard button on it's own, it's very responsive. The buttons in my template are not (very hit and miss).

我创建了一个简单的测试应用程序(见上文)来测试它,我的测试应用程序上的行为是相同的。

I created a simple test application (see above) to test this, and the behaviour on my test app is the same.

当它没有注册时,之前选择的listviewitem仍然被选中,我选择的未注册的项目是浅蓝色(就像你用鼠标悬停时一样) )

When it doesn't register, the previously selected listviewitem is still selected, and the item I have selected that hasn't registered is a light blue (like when you hover over with a mouse)

我们非常感谢任何帮助。

Any help would be greatly appreciated.

推荐答案

Hi Mockingbird11,

Hi Mockingbird11,

>>例如,如果我连续按下列表视图中的10个按钮,则可能会注册7个触摸,3个触摸会赢't。

>>For example, if I press 10 buttons in my list view in a row, maybe 7 touches will register and 3 touches won't.

我只能看到UI文本更改有延迟,因为您通过代码后面访问UI对象,我们建议使用

Dispatcher.Invoke
方法:

I can just see the UI text change has a delay, because you are accessing UI object through code behind, we would suggestion using Dispatcher.Invoke method:

private void Button_Click(object sender,RoutedEventArgs e)
{
Application.Current.Dispatcher.Invoke(new Action(()=> {this.TextBox.Text = this.c ++。ToString(); }));
}

private void Button_Click(object sender, RoutedEventArgs e) { Application.Current.Dispatcher.Invoke(new Action(() => { this.TextBox.Text = this.c++.ToString(); })); }

您是否测试了
TouchDown
方法适用于您的计算机?如果结果相同,硬件/驱动程序问题也是可能的原因。

And have you tested whether the TouchDown method works well on your machine? If the result is the same, the hardware/driver issue is also a possible reason.


这篇关于WPF ListViewItem事件未在触摸屏上正常触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆