Windows Phone上下文菜单项文本未显示

时间:2013-05-17 14:01:59

标签: xaml contextmenu windows-phone

我有一个使用XAML / C#的Windows Phone 8应用程序。我的应用有ItemsControl依赖于数据模板。我的DataTemplate如下所示:

<DataTemplate x:Key="myTemplate">
  <Grid Margin="0,0,0,8">
    <Grid.ColumnDefinitions>
      <ColumnDefinition />
      <ColumnDefinition Width="Auto" />
    </Grid.ColumnDefinitions>

    <Grid VerticalAlignment="Center">
      <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
      </Grid.RowDefinitions>

      <TextBlock Text="{Binding DisplayName}" TextWrapping="NoWrap" Style="{StaticResource PhoneTextLargeStyle}" TextTrimming="WordEllipsis" >
        <toolkit:ContextMenuService.ContextMenu>
          <toolkit:ContextMenu>
            <toolkit:MenuItem x:Name="customerMenuItem" Foreground="White" Header="View Customer Profile" Click="customerMenuItem_Click" Tag="{Binding Path=CustomerName}" />
          </toolkit:ContextMenu>
        </toolkit:ContextMenuService.ContextMenu>
      </TextBlock>
      <TextBlock Text="{Binding Summary}" TextWrapping="NoWrap" Grid.Row="1" Style="{StaticResource PhoneTextSmallStyle}" />
    </Grid>

    <StackPanel Orientation="Horizontal" Grid.Column="1"><!-- Stuff here --></StackPanel>
  </Grid>
</DataTemplate>

DataTemplate在我的XAML的主要部分中引用,如下所示:

<Grid x:Name="ContentPanel" Grid.Row="1" Grid.ColumnSpan="2" Margin="12,0,12,0">
  <ScrollViewer>
    <ItemsControl x:Name="myItemsControl" ItemTemplate="{StaticResource myTemplate}" ItemsSource="{Binding Customers}">
      <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate>
          <StackPanel Orientation="Vertical" />
        </ItemsPanelTemplate>
      </ItemsControl.ItemsPanel>
    </ItemsControl>
  </ScrollViewer>
</Grid>

请注意,“toolkit”命名空间来自clr-namespace:Microsoft.Phone.Controls; assembly = Microsoft.Phone.Controls.Toolkit。当我在TextBlock上握住手指(或鼠标)时,会出现一个上下文菜单。但是,我从未见过“查看客户资料”字样。我只看到一个代表上下文菜单本身的块框。我知道那个项目在那里。我知道因为customerMenuItem_Click事件成功触发了。我在那里有MessageBox,显示了Tag的值。该值始终是正确的。由于某种原因,菜单项文本没有出现。我做错了什么?

1 个答案:

答案 0 :(得分:0)

你放Foreground = "White"。上下文菜单在白色背景。这就是为什么你没有看到你的菜单项。

相关问题