This is a migrated thread and some comments may be shown as answers.

How bind command to DataContext

5 Answers 151 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Miroslav
Top achievements
Rank 1
Miroslav asked on 24 Apr 2016, 02:15 PM

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š

5 Answers, 1 is accepted

Sort by
0
Ivaylo Gergov
Telerik team
answered on 27 Apr 2016, 04:45 PM
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
0
Miroslav
Top achievements
Rank 1
answered on 28 Apr 2016, 04:41 PM

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š

0
Tsvyatko
Telerik team
answered on 03 May 2016, 10:53 AM
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
0
Miroslav
Top achievements
Rank 1
answered on 04 May 2016, 06:44 PM

Hello,

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

Best Regards

Miroslav Mareš

0
Miroslav
Top achievements
Rank 1
answered on 07 May 2016, 08:59 AM

Hello,

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

Best Regards

Miroslav Mareš

Tags
ListView
Asked by
Miroslav
Top achievements
Rank 1
Answers by
Ivaylo Gergov
Telerik team
Miroslav
Top achievements
Rank 1
Tsvyatko
Telerik team
Share this question
or