The following forum(s) have migrated to Microsoft Q&A (Preview): Developing Universal Windows apps!
Visit Microsoft Q&A (Preview) to post new questions.

Learn More

 locked
DelegateCommand<object> is not beeing invoked RRS feed

  • Question

  • Hello again,

    I am using Template10 framework

    I am utilizing a ListView.
    The ViewModel needs to know the SelectedItems.
    The SelectedItems should be passed as a parameter with a converter.
    EventTriggerBehavior EventName="SelectionChanged" is tested working.
    The converter is tested working.
    DelegateCommand> SelectionChangedCommand is NOT working.
    DelegateCommand of anything is NOT working (no string, no int - no nothing).
    DelegateCommand SelectionChangedCommand is tested working.
    Only DelegateCommands without parameter are working when
    ListView -> EventTriggerBehavior -> InvokeCommandAction

    Any ideas why?

    Wednesday, February 17, 2016 10:50 PM

Answers

  • After hours, solution / reason is found:

    The DelegateCommand<T> wasn't the type the XAML was looking for in the ViewModel although it should have been the same.

    I changed the converter which has implemented a new List<T> instead of IList<object> before. SelectedItems are beeing added into the new List and returned.

    The command is of the same type of the returned list and it works.

    Converter:

    public object Convert(object value, Type targetType, object parameter, string language) { var list = new List<string>(); foreach (var item in ((parameter as ListView).SelectedItems)) { list.Add(item as string);

    } return list; }

    Command:

     DelegateCommand<List<string>> _DeleteCommand;
            public DelegateCommand<List<string>> DeleteCommand
               => _DeleteCommand ?? (_DeleteCommand = new DelegateCommand<List<string>>((l) =>
               {
                   if (l != null)
                       foreach (var item in l)
                       {
                           Collection.Remove(item);
                       }
               }, (l) => true));


    • Marked as answer by Marcus Runge Thursday, February 18, 2016 12:18 PM
    • Edited by Marcus Runge Thursday, February 18, 2016 12:19 PM
    Thursday, February 18, 2016 12:18 PM

All replies

  • After hours, solution / reason is found:

    The DelegateCommand<T> wasn't the type the XAML was looking for in the ViewModel although it should have been the same.

    I changed the converter which has implemented a new List<T> instead of IList<object> before. SelectedItems are beeing added into the new List and returned.

    The command is of the same type of the returned list and it works.

    Converter:

    public object Convert(object value, Type targetType, object parameter, string language) { var list = new List<string>(); foreach (var item in ((parameter as ListView).SelectedItems)) { list.Add(item as string);

    } return list; }

    Command:

     DelegateCommand<List<string>> _DeleteCommand;
            public DelegateCommand<List<string>> DeleteCommand
               => _DeleteCommand ?? (_DeleteCommand = new DelegateCommand<List<string>>((l) =>
               {
                   if (l != null)
                       foreach (var item in l)
                       {
                           Collection.Remove(item);
                       }
               }, (l) => true));


    • Marked as answer by Marcus Runge Thursday, February 18, 2016 12:18 PM
    • Edited by Marcus Runge Thursday, February 18, 2016 12:19 PM
    Thursday, February 18, 2016 12:18 PM
  • Hello Marcus,

    It is glad to hear that you got it working and thank you for sharing your solutions & experience here. It will be very beneficial for other community members who have similar questions.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. <br/> Click <a href="http://support.microsoft.com/common/survey.aspx?showpage=1&scid=sw%3Ben%3B3559&theme=tech"> HERE</a> to participate the survey.

    Friday, February 19, 2016 2:37 AM