1

ボタンのコマンドはExcelExportCommandであり、そのCommandParameterは次のようになります。

<Button x:Name="ExcelExport" Grid.Row="1" Height="25" Width="100" Command="{Binding ExcelExportCommand}" CommandParameter="{Binding ElementName=ListTabControl, Path=SelectedIndex}">Export to Excel</Button>

プログラムでViewModelを介してSelectedIndexを取得するにはどうすればよいですか?私はMVVMパターンに不慣れであり、正しいアプローチを取ったことを確認したいと思います。手伝ってくれますか?

前もって感謝します

4

1 に答える 1

1

ListTabControlのSelectedIndexプロパティをビューモデルの整数プロパティにバインドできます。

<List x:Name="ListTabControl" SelectedIndex="{Binding ListSelectedIndex}" />

private int _ListSelectedIndex;
public int ListSelectedIndex {
    get { return _ListSelectedIndex;}
    set
    {
        _ListSelectedIndex = value;
        OnPropertyChanged("ListSelectedIndex"); // if INotifyPropertyChanged implemented
    }
}
于 2012-02-20T08:45:31.650 に答える