簡體   English   中英

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

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

我正在開發一個小型Windows Phone 7 Silver Light應用程序。 我只是希望當用戶點擊並按住相應條目時,上下文菜單會在列表框中的項目上方彈出。 我已經閱讀了幾篇文章,給出的最常見答案是使用Silverlight工具箱。 我很高興,因為我已經設置好它並將其用於應用程序中的其他一些功能。 因此,我找到了一個說明如何在按鈕上進行設置的教程。 嘗試失敗的原因是,我兩次為按鈕設置了內容:

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

這告訴我“屬性'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>

這告訴我“不能將'GestureListener'類型的值添加到'UIElementCollection'類型的集合或字典中。

如果您對方法或全新方法有所幫助,我將不勝感激。 提前致謝!

您需要將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> 

對於它的價值,該工具包已經包含一個ContextMenu幫助器。 這里

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM