0

I have been banging my head on this for a while now! Here is my simple User Control:

<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>

I want to be able to detect touches on the DockPanel or in a possible child of it. Here follows the code behind for the same class, with the alternatives I attempted:

 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; }
}

I do believe I am missing something obvious. Can someone please help me? Thanks.

Tilvia
  • 261
  • 1
  • 4
  • 14

2 Answers2

0
  • The Button & popup needs to be connected to its click (or touch) handlers defined in the code behind, in XAML itself.

  • If you want to handle touch events for the dockpanel, How about adding a button inside the dockpanel with opacity = 0 ??


EDIT : I can see that you defined a few handlers, but did you add those Handlers to the button?

For example, for a SurfaceButton :

IN XAML :

<s:SurfaceButton Click="OpenButton_Click"/>

Correspondingly connects the function in C# as:

private void OpenButton_Click(object sender, RoutedEventArgs e)
{
    // Handle the action for the click here.
}
loxxy
  • 12,990
  • 2
  • 25
  • 56
  • I just tried adding a SurfaceButton, but the problem is still there... And, to clarify the code above, I tried in turn all of the commented out alternatives. Or do you mean that those connections need to be set in XAML only? – Tilvia Nov 16 '11 at 17:31
  • Please see the edits. You can do it in code alone too, but the above will be more intuitive. – loxxy Nov 16 '11 at 17:41
0

Under the covers, Popup creates another hwnd to render its content into. This is different from all other WPF controls. You need to register this hwnd with the Surface SDK so it will start sending touch events to it. Use this to do that: http://msdn.microsoft.com/en-us/library/microsoft.surface.presentation.input.touchextensions.enablesurfaceinput.aspx

Robert Levy
  • 28,747
  • 6
  • 62
  • 94