PointerPressed在左键单击时不起作用

xki*_*lah 17 c# wpf controls microsoft-metro windows-8

在WPF + C#上为Windows 8创建Metro(Microsoft UI)应用程序,我在按钮上遇到了PointerPressed事件的困难.当我执行左键单击(通过鼠标)时不会发生事件,但是在右键单击或点击时会发生这种情况.那个事件有什么问题?例如

 <Button x:Name="Somebutton"  Width="100" Height="100"
PointerPressed="Somebutton_PointerPressed"/>
Run Code Online (Sandbox Code Playgroud)

xki*_*lah 34

解决方案非常简单:这些事件不是通过XAML处理,而是通过AddHandler方法处理.

SomeButton.AddHandler(PointerPressedEvent, 
new PointerEventHandler(SomeButton_PointerPressed), true); 
Run Code Online (Sandbox Code Playgroud)

  • @dcdroid因为在XAML中没有办法设置bool`handdedEventsToo`参数`true`.但是这个参数是重要的细微差别,没有它,在Button内部处理事件并"忽略"你的处理程序 (6认同)
  • 很抱歉,如果这是一个愚蠢的问题,但是它在XAML中声明它的原因是什么? (4认同)