按钮的命令是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模式的新手,我想验证我是否采取了正确的方法。你能帮上忙吗?
提前感谢
发布于 2012-02-20 16:45:32
您可以将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
}
}https://stackoverflow.com/questions/9357763
复制相似问题