我已经在这上面敲了一段时间了!下面是我的简单用户控件:
<UserControl x:Class="DaCapo.MyUserControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:s="http://schemas.microsoft.com/surface/2008"
IsManipulationEnabled="True"
Width="300" Height="300">
<Canvas>
<s:SurfaceButton x:Name="button" Width="100" Height="100" Content="Click!" Style="{x:Null}"/>
<Popup x:Name="popup" Width="200" Height="100" IsOpen="False" StaysOpen="True" PlacementRectangle="0,0,200,100"
AllowsTransparency="True" Focusable="True">
<DockPanel x:Name="dockpanel" Width="200" Height="100" Background="SteelBlue" Focusable="True"/>
</Popup>
</Canvas>
</UserControl>我希望能够检测到DockPanel或其可能的子代中的触点。下面是同一个类的代码,以及我尝试过的备选方案:
public partial class MyUserControl : UserControl
{
public MyUserControl()
{
InitializeComponent();
TouchExtensions.AddHoldGestureHandler(this.button, this.HoldHandler);
/* NONE OF THE FOLLOWING WORKS */
// TouchExtensions.AddTapGestureHandler(this.popup, this.TapHandler);
// this.dockpanel.TouchDown += new System.EventHandler<TouchEventArgs>(popup_TouchDown);
// this.popup.TouchDown += new System.EventHandler<TouchEventArgs>(popup_TouchDown);
// this.popup.ManipulationStarting += new System.EventHandler<ManipulationStartingEventArgs>(popup_ManipulationStarting);
// this.dockpanel.ManipulationStarting += new System.EventHandler<ManipulationStartingEventArgs>(popup_ManipulationStarting);
}
void popup_ManipulationStarting(object sender, ManipulationStartingEventArgs e) { Debug.WriteLine("Tap..."); }
void popup_TouchDown(object sender, TouchEventArgs e) { Debug.WriteLine("Tap..."); }
private void TapHandler(object sender, TouchEventArgs e) { Debug.WriteLine("Tap..."); }
private void HoldHandler(object sender, TouchEventArgs e) { Debug.WriteLine("Holding..."); this.popup.IsOpen = true; }
}我确实认为我遗漏了一些明显的东西。有人能帮帮我吗?谢谢。
发布于 2011-11-17 01:19:57
opacity = 0 ??在停靠面板内添加一个按钮如何??
编辑:我可以看到你定义了一些处理程序,但是你把这些处理程序添加到按钮中了吗?
例如,对于SurfaceButton:
在XAML中:
<s:SurfaceButton Click="OpenButton_Click"/>相应地将C#中的函数连接为:
private void OpenButton_Click(object sender, RoutedEventArgs e)
{
// Handle the action for the click here.
}发布于 2011-11-17 22:50:18
在幕后,Popup创建了另一个hwnd来呈现其内容。这与所有其他WPF控件不同。你需要向Surface SDK注册这个hwnd,这样它才会开始向它发送触摸事件。使用以下代码来实现此目的:http://msdn.microsoft.com/en-us/library/microsoft.surface.presentation.input.touchextensions.enablesurfaceinput.aspx
https://stackoverflow.com/questions/8155704
复制相似问题