Search code examples
wpfpopuptouchpixelsense

SurfaceScrollViewer: getting touch on nested children


I have the following piece of code, which is part of a WPF 4 UserControl:

<Popup x:Name="CantoPopup" IsOpen="False" PlacementRectangle="50,-100,500,120" 
               AllowsTransparency="True" PopupAnimation="Fade" 
               StaysOpen="True" Width="500" Height="120">
            <Border BorderBrush="#FF120403" BorderThickness="1" CornerRadius="10" Background="#FF9350">
                <s:SurfaceScrollViewer x:Name="IndexScroller" Width="500" Height="120" Margin="10" VerticalScrollBarVisibility="Disabled" HorizontalScrollBarVisibility="Visible">
                    <DockPanel x:Name="InnerIndexPanel" />
                </s:SurfaceScrollViewer>
            </Border>
        </Popup>

The DockPanel is then populated in the code-behind with a collection of TextBlocks. Basically, I am trying to build a scrollable horizontal list of touchable items.

Now, I would like to detect which textblock was touched by the user. However, neither adding a TouchDown event handler to the TextBlocks nor using TouchExtensions to handle tap gestures worked. Can someone please point me in the right direction?


Solution

  • 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