1

削除キーを押しても、以下のコマンドは起動しません。View で参照される DelegateCommand の他のインスタンスが ViewModel 内で適切に起動されるため、DelegateCommand はインターフェイス コントラクトに従うと想定できます。

なんで?

意見:

<ListBox Height="132"
     Name="lbFiles"
     ItemsSource="{Binding LbItems, UpdateSourceTrigger=PropertyChanged,ValidatesOnDataErrors=True}"  
     VerticalAlignment="Center"
     SelectedValue="{Binding Path=ListBoxSelection}">
<ListBox.InputBindings>
    <KeyBinding Key="Delete"
                Command="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}
                ,Path=DataContext.CommandInputFilesDeleteSelected}" />
</ListBox.InputBindings>

ビューモデル:

private DelegateCommand commandInputFilesDeleteSelected;

public ICommand CommandInputFilesDeleteSelected {
    get {
            if (commandInputFilesDeleteSelected == null) {
                commandInputFilesDeleteSelected = new DelegateCommand(InputFilesDeleteSelected);
            }
    return saveCommand;
    }
}

private void InputFilesDeleteSelected() { //this never fires :( 
        LbItems.Remove(ListBoxSelection); 
}
4

1 に答える 1

0
private DelegateCommand commandInputFilesDeleteSelected;

public ICommand CommandInputFilesDeleteSelected {
    get {
            if (commandInputFilesDeleteSelected == null) {
                commandInputFilesDeleteSelected = new DelegateCommand(InputFilesDeleteSelected);
            }
    return saveCommand;  //changed from saveCommand to commandInputFilesDeleteSelected whoops
    }
}
于 2013-01-30T21:05:04.177 に答える