2012-03-26 96 views
0

我已經將Silverlight工具包添加到我的WP7應用程序中。WP7中Silverlight工具包的問題

<Button Content="Country"> 
    <toolkit:ContextMenuService.ContextMenu> 
     <toolkit:ContextMenu> 
      <toolkit:MenuItem Header="England" Tag="1" Click="set_country" /> 
      <toolkit:MenuItem Header="Germany" Tag="2" Click="set_country" /> 
      <toolkit:MenuItem Header="France" Tag="3" Click="set_country" /> 
      <toolkit:MenuItem Header="Spain" Tag="4" Click="set_country" /> 
      <toolkit:MenuItem Header="Italy" Tag="5" Click="set_country" /> 
     </toolkit:ContextMenu> 
    </toolkit:ContextMenuService.ContextMenu> 
</Button> 

處理程序:

private void set_country(object sender, MouseEventArgs e) 
{ 
    var menuItem = (MenuItem)sender; 
    var tag = menuItem.Tag.ToString(); 
    MessageBox.Show(tag); 
} 

但它在這個字符串中MainPage.gics問題:

this.LayoutRoot = ((System.Windows.Controls.Grid)(this.FindName("LayoutRoot"))); 

錯誤:無法分配財產「Microsoft.Phone.Controls。 MenuItem.Click」。 [行:31職位:72]

+1

請不要發誓。我不知道wp7工具包,但你對mouseeventargs是否正確?不應該是RoutedEventargs? – Silvermind 2012-03-26 16:32:50

回答

2

事件處理程序的簽名是錯誤的:

private void MenuItem_Click(object sender, RoutedEventArgs e) 
{ 
    MenuItem menuItem = (MenuItem)sender; 
    MessageBox.Show("You chose to " + menuItem.Header.ToString(),"Result",MessageBoxButton.OK); 
} 
相關問題