How bind command to DataContext

6 posts, 0 answers
  1. Miroslav
    Miroslav avatar
    30 posts
    Member since:
    Feb 2012

    Posted 24 Apr Link to this post

    Hello,

    I have specific VM, that I must set as page datacontext in OnNavigatedTo event. In xaml I have hubsection with listview. In listview I have command for ItemTap. I want define command that binds to page datacontext, but I don't known how. All my attempts ended with now response on list item tap. Can you help me please?

    Best Regards

    Miroslav Mareš

  2. Ivaylo Gergov
    Admin
    Ivaylo Gergov avatar
    661 posts

    Posted 27 Apr Link to this post

    Hello,

    You can take advantage of RadListView.Commands collection and define a ListViewUserCommand with ItemTap id and bind its Command property to an ICommand from your model.

    I hope this helps.
    Regards,
    Ivaylo Gergov
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. DevCraft banner
  4. Miroslav
    Miroslav avatar
    30 posts
    Member since:
    Feb 2012

    Posted 28 Apr in reply to Ivaylo Gergov Link to this post

    Hello,

    you don't understand me. I have in xaml this:

    <telerikDataControls:RadListView.Commands>
    <telerikListViewCommands:ListViewUserCommand Id="ItemTap" Command="{Binding Expenses.EditVehicleExpenseCommand}" EnableDefaultCommand="False"/>
    </telerikDataControls:RadListView.Commands>

    But in this way command does not have DataContext from ListView. I cannot define context as static source, while I assign viewmodel in event OnNavigatedTo, it's dynamic and not static. So I don't known, how should I defined it.

    Best Regards

    Miroslav Mareš

  5. Tsvyatko
    Admin
    Tsvyatko avatar
    832 posts

    Posted 03 May Link to this post

    Hi Miroslav,

    Thank you for clarifying the scenario. I have prepared sample project utilizing custom commands demonstrating how this can be achieved.

    Let us know if this helps.

    Regards,
    Tsvyatko
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  6. Miroslav
    Miroslav avatar
    30 posts
    Member since:
    Feb 2012

    Posted 04 May in reply to Tsvyatko Link to this post

    Hello,

    thank you for example. This solution occurred to me too, but... seems to me too complicated :-/

    Best Regards

    Miroslav Mareš

  7. Miroslav
    Miroslav avatar
    30 posts
    Member since:
    Feb 2012

    Posted 07 May in reply to Tsvyatko Link to this post

    Hello,

    your solution is more universal, than I thought before. It's good for me, thank you.

    Best Regards

    Miroslav Mareš

Back to Top
DevCraft banner