<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次触摸则没有。
如果我单独触摸一个标准按钮,则非常灵敏。但我的模板中的按钮则没有(很容易出现问题)。
我创建了一个简单的测试应用程序(见上文),测试应用程序的行为与我的应用程序相同。
当触摸未被注册时,之前选定的listviewitem仍然被选中,而我选择但未被注册的项目会变成浅蓝色(就像在鼠标悬停时一样)。
如有帮助,将不胜感激。