Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1495
XamGrid conditional formating
posted

Hi,

We use XamGrid to display records with conditional formatting with auto generated columns its working with following steps.

  1. Our all columns are auto generated.
  2. In ColumnAutoGenerated event we use 'ConditionalFormattingRuleBase' and 'ConditionalFormattingRuleBaseProxy'.
  3. Its working fine and we achieve our desired results. Results are showing in snapshots.
  4. In one scenario we use GroupColumn in xaml for grouping of columns. In this case we defined all possible columns in xaml and we set AutoGenerateColumns="False".
  5. Now in this case we need a converter who will work like we did in ColumnAutoGenerated event.
  6. Is there any way to write a converter with GroupColumns that are defined in xaml.
  7. We use DataTable with double type of columns for XamGrid binding and use FormatString="{}{0:#0.0}%".
  8. We use DBNull.Value for empty cells.
  9. This FormatString="{}{0:#0.0}%" append '%' in empty cells. 
  10. How we get rid of it ?
  11. Empty cell are highlighted with red circled. 
  12. Small sample application is very helpful for me.
Parents
  • 34510
    Verified Answer
    Offline posted

    Hi elinder,

    I wasn't sure which kind of ConditionalFormattingRuleBase you are using so I used a simple one just to illustrate how you would do this.

    Basically, since you are declaring all of these columns in XAML, you can just create the rules in XAML as well. http://help.infragistics.com/doc/WPF/2014.2/CLR4.0/?page=xamGrid_Conditional_Formatting.html

    This, however, may add quite a bit of extra XAML so you might be inclined to do it programmatically in code-behind.  For that you should handle the ColumnLayoutAssigned event and then iterate over the GroupColumns, then iterate over the GroupColumn.Columns collection and assign your conditional rules accordingly.  I have attached a sample that demonstrates this.

    As for the FormatString percent symbol, how you handle this depends on what you want to occur.  Underneath the hood, the XamGrid cell is just using normal Microsoft string formatting so what you are seeing is pretty much expected.  In order to deal with this, I created a style for TextBlock and added a DataTrigger to the cell value.  When the cell value is null, it sets the TextBlock's Visibility to Collapsed.  This style is then assigned to the TextColumn.TextBlockStyle property.  You can see this in the sample as well.

    Let me know if you have any questions.

    XamGridConditionalFormatting.zip
Reply Children
No Data