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
4970
how to put ConditionalFormatCollection as a cell style in App.xaml and apply it for a column in code?
posted

I want to set up ConditionalFormatCollection  for a TextColumn in XamGrid like:
<ig:TextColumn.ConditionalFormatCollection>
    <ig:EqualToConditionalFormatRule Value="ABC">
      <ig:EqualToConditionalFormatRule.StyleToApply>
          <Style TargetType="ig:ConditionalFormattingCellControl">
                <Setter Property="Foreground" Value="Green" />
                      <Setter Property="FontWeight" Value="SemiBold" />
          </Style>
      </ig:EqualToConditionalFormatRule.StyleToApply>
   </ig:EqualToConditionalFormatRule>

   <ig:EqualToConditionalFormatRule Value="XYZ">
      <ig:EqualToConditionalFormatRule.StyleToApply>
          <Style TargetType="ig:ConditionalFormattingCellControl">
                <Setter Property="Foreground" Value="Red" />
                      <Setter Property="FontWeight" Value="SemiBold" />
          </Style>
      </ig:EqualToConditionalFormatRule.StyleToApply>
   </ig:EqualToConditionalFormatRule>

</ig:TextColumn.ConditionalFormatCollection>
It has no problem to put in xaml in user control directly. But I want to put it in app,xaml as a cell style, and then use it in code for any XamGrid based on the data loaded. How to implement this request?

It has no problem to put in xaml in user control directly. But I want to put it in app,xaml as a cell style, and then use it in code for any XamGrid based on the data loaded. How to implement this request?

here is my testing:

1. created style and put it app.xml:

  <Style TargetType="ig:ConditionalFormattingCellControl" x:Key="ABC">
        <Setter Property="Foreground" Value="Green" />
        <Setter Property="FontWeight" Value="SemiBold" />
  </Style>

  <Style TargetType="ig:ConditionalFormattingCellControl" x:Key="XYZ">
        <Setter Property="Foreground" Value="Red" />
        <Setter Property="FontWeight" Value="SemiBold" />
  </Style>

2. in xaml for user control, the column is

<ig:XamGrid.ConditionalFormattingSettings>
        <ig:ConditionalFormattingSettings AllowConditionalFormatting="True" />
    </ig:XamGrid.ConditionalFormattingSettings>
...

<ig:TextColumn Key="MyColumn" >
    <ig:TextColumn.HeaderTemplate>
        <DataTemplate>
          <TextBlock Text="MyColumn" />
        </DataTemplate>
    </ig:TextColumn.HeaderTemplate>
</ig:TextColumn>

3. in code, try to apply above style:


        ConditionalFormatCollection coll = new ConditionalFormatCollection();
            coll.Add(new EqualToConditionalFormatRule()
            {
                Value = "ABC",
                StyleToApply = Application.Current.Resources["ABC"] as Style,                
            });
            coll.Add(new EqualToConditionalFormatRule()
            {
                Value = "XYZ",
                StyleToApply = Application.Current.Resources["XYZ"] as Style
            });
            // Add Rule to the UnitsInStock Column
            grid.Columns.DataColumns["MyColumn"].ConditionalFormatCollection = coll;

then run the app for testing, it is not working.  Help please. Thanks.