Question

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

Was it helpful?

Solution

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
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top