Hi, I am trying to display a dataPresenter (using MVVM with minimal code in codebehind) that depends on the number of elements to determine if it is displayed as a Grid or in Cardview.
If there is only one element in the BindingList, I want to show Cardview with the following fields:
<igDP:Field Name="Description" Label="Description" Row="0" Column="0" Width="*"/>
<igDP:Field Name="Market" Label="Country of Incorp:" Row="1" Column="0" Width="*"/>
<igDP:Field Name="Mkt" Label="Tax Country:" Row="2" Column="0" Width="*"/>
<igDP:Field Name="RecordDate" Label="Record Date" Row="3" Column="0" Width="*"/>
<igDP:Field Name="Ticker" Label="Ticker" Row="0" Column="1" Width="*"/>
<igDP:Field Name="Sedol" Label="Sedol" Row="1" Column="1" Width="*"/>
<igDP:Field Name="Cusip" Label="CUSIP" Row="2" Column="1" Width="*"/>
However, if there is more than one element to display, I would like to show it in a traditional grid, where each row represents a different element (and all the columns are simply next to eachother).
I haven't seen a sample yet where the columns are explicitly defined for cardview vs. grid view, and I haven't really seen a sample that declares the datapresenter view from the viewmodel.
Can you please help? Thanks in advance.
Hello Christian,
I am just checking about the progress of this issue. Please let me know if you need any further assistance on this.
Thank you for your post.
I have been looking into your issue I can suggest creating a class that derives from XamDataGrid and you can create a method in it, that checks the count of the DataSource and if it there is only one item, it set the view to a CardView and if there are more items, sets the View to a GridView. You can override the OnPropertyChanged of the XamDataPresenter, and there, you can check the e.Property and if it is the DataSource to call the method to update the view. Also, in order to be able to update the view while adding/removing items in the DataSource at runtime, you can use the OnPropertyChanged to check whether the e.NewValue is INotifyCollectionChanged and if yes, to handle its CollectionChanged event, where you can update the view also.. I have created a sample application for you that shows how cam implement this approach.
Please let me know if you need any further assistance on the matter.