Hello,
I have a XamDataGrid in use and would like to have several Background Colors for rows, depending on f.e. a viewModels Backgroud Color Property. Here you can see how i defined it in xaml. Can u please give me some hints or sample code to solve my problem?
<igGrids:TextColumn PropertyPath="F200" TextColor="White" Background="Gray" HeaderText="{Binding DataGridHeader.F200}" IsHidden="{Binding DataGridHeader.F200, Converter={StaticResource StringToHiddenConverter}}"> <igGrids:TextColumn.Header> <igGrids:TextHeader FontAttributes="Bold" /> </igGrids:TextColumn.Header> </igGrids:TextColumn>
Hello Martin,
I am under the impression that you are looking to set multiple background colors for different cells in the same column in this case. If this is incorrect, please let me know as the following is based upon this impression.
Currently, setting the Background color on your TextColumn will blanket each of the cells in that column in the same color, and so binding that property will not help you here. Instead, I would recommend usage of the DataBound event which exists on each column in the Infragistics for Xamarin XamDataGrid.
In the DataBound event, you can check the event arguments to get the CellInfo for each cell as its underlying data is data bound. This CellInfo element has a RowItem property that you can use to get the underlying data item for your data grid's row. Checking it, you can assign a new Background to your CellInfo object based on your underlying data item or ViewModel. The following example code may help you to achieve this:
SolidColorBrush yellow = new SolidColorBrush(Color.Yellow); SolidColorBrush liteBlue = new SolidColorBrush(Color.LightBlue); private void TextColumn_DataBound(object sender, Infragistics.XamarinForms.Controls.Grids.DataBindingEventArgs args) { if(args.CellInfo != null) { var x = args.CellInfo.RowItem; if (x != null) { SampleGridData data = x as SampleGridData; if (data.ID % 2 == 0) { args.CellInfo.Background = yellow; } else { args.CellInfo.Background = liteBlue; } } } }
It is worth noting that the Infragistics for Xamarin XamDataGrid currently styles its rows on a cellular basis, and so if you wish to do this for your entire row, you will need to handle this event for each column in your grid.
I hope this helps. Please let me know if you have any other questions or concerns on this matter.
Sincerely,AndrewAssociate Developer
Hi Andrew,
so syling a whole row in f.e. green background color and another row f.e. in red background color will end up like this, or? I also wondered that you can't set a row backgroundcolor or bind it to a property...
If you have another solution to set different background colors for each row, please let me know. Thank u very much!
Sincerely, Martin
It is a fair assumption that styling an entire row would essentially end up like this at the moment.
The Infragistics for Xamarin XamDataGrid does not currently really have a way to style the entirety of a "Row" as the styling is currently done on a cell-by-cell basis. That said, if you style all of the cells of a particular row using the event mentioned above on each of the columns in your grid, you can essentially style the entire row.
If you would like to see a way to style the entirety of the rows in the Infragistics for Xamarin XamDataGrid, I would recommend suggesting a new product idea for this by e-mailing ideas@infragistics.com. This will place you in direct communication with our product management teams who plan and prioritize upcoming features and development based on community and user feedback.
Please let me know if you have any other questions or concerns on this mater.
args.CellInfo.RowItem is always null as args.RowObject is always null, too :( Do you have any hints solving this problem? Will RowItem only be filled when AutoGenerateColums is set to true? Sincerely, Martin
I have put together a sample project using the code that I provided above, and the behavior am seeing is that args.CellInfo.RowItem and args.RowObject are null the first few times the DataBound event fires, but these items are eventually not null. This is likely because this event will fire whenever a cell is updated, and on startup of the Xamarin XamDataGrid, these items are not yet "initialized" or assigned.
I am attaching the sample project I used to test this. Please test this project on your PC; whether or not it works correctly may help indicate the nature of this problem.
If the project does not work correctly, this indicates either a problem possibly specific to your environment, or a difference in the DLL versions we are using. My test was performed using version 17.2.20172.2051 in Infragistics for Xamarin.Forms 2017.2.
If the project does show the product feature working correctly, this indicates a possible problem in the code of your application. It will help if you can provide a small, isolated sample application that demonstrates the behavior you are seeing.
Or, if this sample project is not an accurate demonstration of what you're trying to do, please feel free to modify it and send it back, or send a small sample project of your own if you have one.
Please let me know if you have any other questions or concerns on this matter.
2620.XFGridColors.zip
Hello Andrew,
thanks four your Support!
The First Problem "RowObject/Item == null" has been solved :-)
But there is another Problem :
Imagine you have a xamdatagrid where you have many columns, like 10, with a width of 100px.
What happens is, that you have to scroll horizontal and DataBound will also be fired with the effect, that Background Colors will be cleared.
Any Suggestions?
3326.XFGridColors.zip
I've Extended your sample Project with this Scenario.
Sincerely,
Martin Kleinod
I have been investigating into the modified sample project you have provided, and I have reproduced this behavior you are referring to.
I have attempted to devise a few workarounds, first by utilizing the args.CellInfo.DataRow, which is the index of the row and would correspond to the underlying data item's index in your collection. This works well for the columns that are initially in view, but unfortunately returns -1 consistently for the horizontally-scrolled columns.
As an alternative, I also tried utilizing the TemplateColumn and using a converter bound to the RowItem in the ContentTemplate or binding directly to "RowItem.<PropertyName>" where <PropertyName> is a Xamarin.Forms.Color property, storing the would-be row color. Again, both of these options work initially, but after horizontally scrolling, they fail.
This leads me to believe that there is an all-round issue with setting of the Row and Cell information for horizontally scrolled columns, and I have notified our development teams as such. To ensure this issue receives attention, I have logged it in our internal tracking systems with a development ID of 247041.
I have also created a private support case for you that I will link development issue 247041 to. This support case has an ID of CAS-189264-J2H4N8 and you can access it after signing into your account on the Infragistics website at https://www.infragistics.com/my-account/support-activity.