帮助!
在我正在开发的wpf应用程序中使用Touch事件时遇到问题摔跤。
让我设置场景......
我有一个主窗口(fmMainWindow),上面有一个文本框。打开时,窗口被编码为以屏幕为中心。在Textbox的TouchUp事件中,我有使用语法ShowDialog打开另一个窗口(fmKeypad_Numeric)的代码。该窗口也居中。它是一个数字小键盘,上面有编号按钮。
我的问题是主窗口上使用的触摸事件对它打开的窗口上的按钮的Click事件有影响。
看起来触摸事件发生在屏幕上的任何地方,下一个窗口上的按钮在同一位置打开似乎最初有某种焦点' (好像鼠标悬停在它上面)。
如果您点击最初具有焦点'的按钮,则点击事件会按预期触发。
但是,如果您首先点击其他一个没有关注焦点的按钮。它的点击事件不会触发。需要再次点击才能触发?
我已经使用Snoop来查看事件是如何触发的,以及当您点击其他按钮之一时,这些按钮最初没有'焦点',与具有&#的按钮相关的事件39;聚焦'火??
有人有任何想法吗?我在这个上花了好几天。
两个窗口的代码在
之下非常感谢,
Rhyd。
<Window x:Class="fmMainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Main Window" SizeToContent="WidthAndHeight" ResizeMode="NoResize" FontFamily="Century Gothic">
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="0">
<TextBox Name="tbTest" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="180,10,10,0" Width="150" Height="50" BorderBrush="#FF1B378B" Background="#FFEC1212"/>
</Grid>
Public Class fmMainWindow
Public Sub New()
' This call is required by the designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
Me.WindowStartupLocation = Windows.WindowStartupLocation.CenterScreen
End Sub
Private Sub tbTest_TouchUp(sender As Object, e As TouchEventArgs) Handles tbTest.TouchUp
e.Handled = True
Dim myKeypad As New fmKeypad_Numeric()
myKeypad.ShowDialog()
myKeypad.Close()
End Sub
End Class
fmKeypad_Numeric
<Window x:Class="fmKeypad_Numeric"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Keypad_Numeric" SizeToContent="WidthAndHeight" ResizeMode="NoResize" FontFamily="Century Gothic" FontSize="30" Left="10">
<Window.Resources>
<Style TargetType="{x:Type Button}" BasedOn="{StaticResource {x:Type Button}}">
<Setter Property="Height" Value="70" />
</Style>
</Window.Resources>
<Grid Name ="grKeypad" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<TextBox Name="tbNumber" HorizontalAlignment="Left" VerticalAlignment="Top" HorizontalContentAlignment="Right" Text="" Width="230" IsReadOnly="True" Margin="10,10,0,0"/>
<Button Name="bu7" Content="7" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10,70,0,0" Width="70" />
<Button Name="bu8" Content="8" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="90,70,0,0" Width="70" />
<Button Name="bu9" Content="9" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="170,70,10,0" Width="70" />
<Button Name="bu4" Content="4" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10,150,0,0" Width="70" />
<Button Name="bu5" Content="5" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="90,150,0,0" Width="70" />
<Button Name="bu6" Content="6" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="170,150,10,0" Width="70" />
<Button Name="bu1" Content="1" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10,230,0,0" Width="70" />
<Button Name="bu2" Content="2" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="90,230,0,0" Width="70" />
<Button Name="bu3" Content="3" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="170,230,10,0" Width="70" />
<Button Name="bu0" Content="0" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10,310,0,0" Width="70" />
</Grid>
Public Class fmKeypad_Numeric
Public Sub New()
' This call is required by the designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
Me.WindowStartupLocation = Windows.WindowStartupLocation.CenterScreen
End Sub
Private Sub Button_Click(sender As Object, e As RoutedEventArgs) Handles bu0.Click, bu1.Click, bu2.Click, bu3.Click, bu4.Click, bu5.Click, bu6.Click, bu7.Click, bu8.Click, bu9.Click
Dim myButtonName As String
Dim myTextToAdd As String = ""
myButtonName = CType(sender, Button).Name
myTextToAdd = Replace(myButtonName, "bu", "")
Me.tbNumber.Text = Me.tbNumber.Text & myTextToAdd
End Sub
End Class