我想为列表视图项设置上下文菜单。所以我添加了上下文菜单,但是单击右键时上下文菜单没有打开。我的事件被调用但后来也没有显示上下文菜单。
我已经读过这样的问题,但没有任何解决方案适合我。
这是我的代码:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="6*" />
<ColumnDefinition Width="4*" />
</Grid.ColumnDefinitions>
<!-- Calendar -->
<telerikInput:RadCalendar x:Name="uiCalendar" Grid.Column="0" SelectionChanged="uiCalendar_SelectionChanged">
</telerikInput:RadCalendar>
<ListView x:Name="uiAppointmentsList" Grid.Column="1" Header="Appointments" RightTapped="uiAppointmentsList_RightTapped"
Background="Transparent" >
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
</Style>
</ListView.ItemContainerStyle>
<ListView.Resources>
<MenuFlyout x:Name="uiMenuFlyout">
<MenuFlyout.Items>
<MenuFlyoutItem x:Name="uiEdit" Text="Edit" />
<MenuFlyoutItem Text="Delete" />
</MenuFlyout.Items>
</MenuFlyout>
</ListView.Resources>
<ListView.ItemTemplate>
<DataTemplate>
<Grid Height="50" Margin="0,3,0,3">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="3*"/>
<ColumnDefinition Width="6*"/>
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<TextBlock Text="{Binding StartDate}" HorizontalAlignment="Left" VerticalAlignment="Top" Grid.Column="1" Grid.RowSpan="2" Margin="0,-5,0,0"/>
<TextBlock Text="{Binding Subject}" FontWeight="Bold" Margin="0, -3, 0, -3" Grid.Column="2"/>
<TextBlock Grid.Row="1" Text="{Binding Location}" Margin="0, -5, 0, 0" Grid.Column="2"/>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
以下是代码中的tapped事件:
private void uiAppointmentsList_RightTapped(object sender, Windows.UI.Xaml.Input.RightTappedRoutedEventArgs e)
{
UIElement listView = (UIElement)sender;
uiMenuFlyout.ShowAt(listView, e.GetPosition(listView));
var a = ((FrameworkElement)e.OriginalSource).DataContext;
}
请建议我出错的地方。
谢谢