我正在使用 Microsoft.Phone.Controls.Toolkit 中的 ContextMenu:
xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
并想通过 DeleteCommand 删除 ListBoxItem
<ListBox ItemsSource="{Binding Items}">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemTemplate>
<DataTemplate>
<Grid>
<toolkit:ContextMenuService.ContextMenu>
<toolkit:ContextMenu >
<toolkit:MenuItem Header="Delete" Command="{Binding DeleteCommand}" CommandParameter="????"/>
</toolkit:ContextMenu>
</toolkit:ContextMenuService.ContextMenu>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding Name}" HorizontalAlignment="Left" VerticalAlignment="Center" TextWrapping="Wrap"/>
<toolkit:ToggleSwitch Grid.Column="1" HorizontalAlignment="Right" VerticalAlignment="Center"/>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
删除命令:
public ICommand DeleteCommand
{
get
{
return new MvxCommand<BulbItem>(item =>
{
_collectionService.Delete(item);
Close(this);
});
}
}
如何将绑定到 BulbItems 列表的 ListBoxItem 传递到 DeleteCommand?
提前致谢!