Search code examples
bindinguwpinticommand

Send int? parameter to command UWP


I have a list ListView type. Current selected index of list is binded to int? property. I want to send selected index as parameter to Execute method of ICommand interface like that:

CommandParameter="{x:Bind ViewModel.SelectedIndex}"

When i debug execute method, debugger is tell that parameter is null. But selected index is have value. How can i send binded int? parameter to this method? Thanks!


Solution

  • CommandParameter="{x:Bind ViewModel.SelectedIndex, Mode=OneWay}"
    

    use mode = oneway so that u can get updated value of selected index everytime it changes. Also make sure your ViewModel implements INotifyPropertyChanged for this to work properly. https://learn.microsoft.com/en-us/uwp/api/windows.ui.xaml.data.inotifypropertychanged