简体   繁体   English

WP7 Silver Light Gesture Listener可以添加到StackPanel吗?

[英]Can WP7 Silver Light Gesture Listener be added to a StackPanel?

I'm working on a small Windows Phone 7 Silver Light app. 我正在开发一个小型Windows Phone 7 Silver Light应用程序。 I simply want a context menu to pop up over an item in a Listbox when the user taps and holds on the respective entry. 我只是希望当用户点击并按住相应条目时,上下文菜单会在列表框中的项目上方弹出。 I've read through several posts and the most common answer given is to use the Silverlight toolkit. 我已经阅读了几篇文章,给出的最常见答案是使用Silverlight工具箱。 I was excited since I already have it set up and use it for a few other things in the app. 我很高兴,因为我已经设置好它并将其用于应用程序中的其他一些功能。 So I found a tutorial that explains how to set it up on a button. 因此,我找到了一个说明如何在按钮上进行设置的教程。 It failed when I tried because I was setting the content for the button twice: 尝试失败的原因是,我两次为按钮设置了内容:

    <Button Width="Auto" MinWidth="460" Height="Auto" HorizontalAlignment="Stretch">
        <Button.Content>
            <toolkit:GestureListener Hold="GestureListener_Hold" />
            <StackPanel ..... >
                .......
            </<StackPanel>
        </Button.Content>
    </Button>

Which tells me "The property 'Content' is et more than once. So after searching again I found a nice article, http://forums.create.msdn.com/forums/t/85263.aspx , which shows that I can move the statement to look more like: 这告诉我“属性'Content'不止一次。因此,在再次搜索后,我发现了一篇不错的文章, http://forums.create.msdn.com/forums/t/85263.aspx ,它表明我可以移动语句,使其看起来更像:

    <StackPanel Orientation.....>
        <toolkit:GestureListener Hold="GestureListener_Hold" />  
        <TextBlock
            Text="{Binding ItemName}" FontSize="{StaticResource PhoneFontSizeLarge}"
            HorizontalAlignment="Stretch" VerticalAlignment="Center" Height="40"/>
    </StackPanel>

Which tells me "A value of type 'GestureListener' cannot be added to a collection or dictionary of type 'UIElementCollection'. 这告诉我“不能将'GestureListener'类型的值添加到'UIElementCollection'类型的集合或字典中。

I'd appreciate any help on either method or a brand new one. 如果您对方法或全新方法有所帮助,我将不胜感激。 Thanks in advance! 提前致谢!

You need to set the GestureListener as the value of the GestureService.GestureListener attached property: 您需要将GestureListener设置为GestureService.GestureListener附加属性的值:

<Button Width="Auto" MinWidth="460" Height="Auto" HorizontalAlignment="Stretch"> 
    <Button.Content> 
        <StackPanel ..... > 
            <toolkit:GestureService.GestureListener>
                <toolkit:GestureListener Hold="GestureListener_Hold" />
            </toolkit:GestureService.GestureListener>
            ....... 
        </<StackPanel> 
    </Button.Content> 
</Button> 

For what it's worth, the toolkit already includes a ContextMenu helper. 对于它的价值,该工具包已经包含一个ContextMenu帮助器。 See here 这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM