2012-07-13 47 views
0

我正在研究一個小型Windows Phone 7 Silver Light應用程序。當用戶點擊並保存相應條目時,我只需要一個上下文菜單彈出列表框中的項目。我已經閱讀了幾篇文章,最常見的答案是使用Silverlight工具包。我很興奮,因爲我已經設置並在應用程序中使用它來做其他事情。所以我找到了一個教程來解釋如何在一個按鈕上進行設置。因爲我設置按鈕的內容兩次失敗時,我想:。可以將WP7 Silver Light手勢監聽器添加到StackPanel中嗎?

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

還告訴我,「屬性‘內容’是等不止一次 所以再次搜索後,我找到了一個不錯的文章,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’的字典。

我會很感激任何方法或全新的幫助。 在此先感謝!

回答

0

您需要設置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> 

對於它的價值,該工具包已包含文本菜單幫手。見here

+0

太棒了!感謝您及時的回覆!我知道它必須是我忽視的簡單東西。 – bergermeister 2012-07-13 19:37:46

+0

沒問題...別忘了給你的服務員打電話(即接受答案)。寶貝需要一個新的徽章...;) – 2012-07-13 19:40:37

+0

我用你發佈的ContextMenu助手去了,使它更容易:) – bergermeister 2012-07-13 20:16:01