SurfaceScrollViewer: getting touch on nested children

自作多情 提交于 2019-12-11 02:48:09

问题


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?


回答1:


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




回答2:


I found out that the point is that the Popup component has some peculiarities :) In this case, it seems that it did not detect neither TouchDown events nor PreviewTouchDown ones. Therefore, I resorted to creating a UserControl made of a Canvas containing the code above and then making such control visible on top of the rest whenever I needed the popup to open. I do not know whether this is the best solution, but now it reacts as expected.



来源:https://stackoverflow.com/questions/8141350/surfacescrollviewer-getting-touch-on-nested-children

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!