문제

A button's Command is ExcelExportCommand and its CommandParameter is like:

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

How can i get the SelectedIndex through a ViewModel programmatically? I'm new to MVVM pattern and I want to verify that I had taken the right approach. Can you help?

Thanks in advance

도움이 되었습니까?

해결책

You can bind the SelectedIndex property of your ListTabControl to an integer property in your viewmodel:

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

private int _ListSelectedIndex;
public int ListSelectedIndex {
    get { return _ListSelectedIndex;}
    set
    {
        _ListSelectedIndex = value;
        OnPropertyChanged("ListSelectedIndex"); // if INotifyPropertyChanged implemented
    }
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top