1

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 に渡すにはどうすればよいですか?

前もって感謝します!

4

2 に答える 2