WPF SelectedIndex CommandParameter
-
28-10-2019 - |
Question
est ExcelExportCommand et son CommandParameter est comme commande de bouton:
<Button x:Name="ExcelExport" Grid.Row="1" Height="25" Width="100" Command="{Binding ExcelExportCommand}" CommandParameter="{Binding ElementName=ListTabControl, Path=SelectedIndex}">Export to Excel</Button>
Comment puis-je obtenir le SelectedIndex par un ViewModel programme? Je suis nouveau modèle MVVM et je veux vérifier que j'avais pris la bonne approche. Pouvez-vous aider?
Merci à l'avance
La solution
Vous pouvez lier la propriété SelectedIndex de votre ListTabControl à une propriété entière dans votre 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
}
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow