Hello, I am a teacher and I am creating my first Xamarin app. I am using Prism for my MVVM framework and one of your grids. I have a screen listing all the sections I teach (bound to an observable collection in my view model). When the I select a section and click on a button I want to navigate to a page with a list of students in that section.
The trouble is that I don’t know what row was selected when I am in my view model. I don’t want to go into the code behind as shown in the documentation. I thought there would be a property in the grid (selected items?) that I could bind to my view model so that when I click the button I would know what section had been selected.
What would be the best way to achieve this with the Infragistics grid?
Hello Jim,
I have been investigating into the behavior you are trying to achieve in this case, and currently the selected item of the XamDataGrid in Infragistics for Xamarin.Forms is not bindable, as the SelectedItems and SelectedKeys properties are not bindable properties.
While these properties are not bindable at the moment, this is not to say that the selected items cannot be kept track of in an MVVM way. I would recommend continuing with what is listed in our documentation, but handle the SelectedItemsChanged event in a Behavior<XamDataGrid> that you can then add to the XamDataGrid.Behaviors collection. This will allow you to keep track of the selected items in an MVVM way. There is a good example of usage of Xamarin.Forms Behaviors here.
Please let me know if you have any other questions or concerns on this matter.
Thanks for your help. My plan now is to use the attached behavior to publish an event with the value of the selected session. The view model will receive the event and store the latest selected session. My xaml do not what to see me attached behavior.
Dumb mistake. Did NOT have the namespace in xmlns declaration.
Looking at the code that you have provided, everything looks ok with the exception of the way that you are currently applying your behavior. Rather than applying it in the way that you currently are, I would recommend usage of the following code:
<igDataGrid:XamDataGrid> <igDataGrid:XamDataGrid.Behaviors> <local:MyBehavior/> </igDataGrid:XamDataGrid.Behaviors> </igDataGrid:XamDataGrid>
This should allow you to apply your behavior correctly.
Thanks, I tried that but I still get the same error. I will submit a support ticket.