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 回答