Hello,
I would like to add a image in a xamGrid Cell like a triangle as we can have in Excel for a formula.
Do you know how to do it only in code behind ? I have the example with Xaml but as my columns are built dynamically I have to do it in code behind.
Best Regards
When I add a break point into the convertor method there is only few callback, we are very far from having one call per cell displayed.
I succeed to add the Image but the display is bugging when I use the mouse lift. The converter is not anymore callbacked. But it works when I use the mouse wheel. So I don't understand why there is a different behavior between the wheel and the lift
<converter:ConverterObjectToVisibility x:Key="converterObjectToVisibility" />
<Style TargetType="ig:CellControl" x:Key="styleYellow"> <Setter Property="Background" Value="Yellow"></Setter> <Setter Property="Height" Value="30" /> <Setter Property="BorderBrush" Value="{StaticResource CellItemNormalBorderBrush}"/> <Setter Property="BorderThickness" Value="0"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="ig:CellControl"> <Grid> <VisualStateManager.VisualStateGroups> <VisualStateGroup x:Name="CommonStates"> <VisualState x:Name="Normal" /> <VisualState x:Name="MouseOver"> <Storyboard > <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00" Storyboard.TargetName="AltMouseOver" Storyboard.TargetProperty="Fill"> <DiscreteObjectKeyFrame KeyTime="00:00:00" Value="{StaticResource CellRowHoverBackgroundBrush}"/> </ObjectAnimationUsingKeyFrames> </Storyboard> </VisualState> <VisualState x:Name="Alternate" > <Storyboard> <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00" Storyboard.TargetName="AltMouseOver" Storyboard.TargetProperty="Fill"> <DiscreteObjectKeyFrame KeyTime="00:00:00" Value="{StaticResource CellItemAltNormalBackgroundBrush}"/> </ObjectAnimationUsingKeyFrames> </Storyboard> </VisualState> </VisualStateGroup> <VisualStateGroup x:Name="SelectedStates"> <VisualState x:Name="NotSelected" /> <VisualState x:Name="Selected"> <Storyboard > <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00" Storyboard.TargetName="ActiveSelected" Storyboard.TargetProperty="Background"> <DiscreteObjectKeyFrame KeyTime="00:00:00" Value="{StaticResource CellItemSelectedBackgroundBrush}"/> </ObjectAnimationUsingKeyFrames> <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00" Storyboard.TargetName="ActiveSelected" Storyboard.TargetProperty="BorderThickness"> <DiscreteObjectKeyFrame KeyTime="00:00:00" > <DiscreteObjectKeyFrame.Value> <Thickness>0</Thickness> </DiscreteObjectKeyFrame.Value> </DiscreteObjectKeyFrame> </ObjectAnimationUsingKeyFrames> </Storyboard> </VisualState> </VisualStateGroup> <VisualStateGroup x:Name="ActiveStates"> <VisualState x:Name="InActive" /> <VisualState x:Name="Active"> <Storyboard > <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00" Storyboard.TargetName="ActiveSelected" Storyboard.TargetProperty="BorderThickness"> <DiscreteObjectKeyFrame KeyTime="00:00:00"> <DiscreteObjectKeyFrame.Value> <Thickness>0</Thickness> </DiscreteObjectKeyFrame.Value> </DiscreteObjectKeyFrame> </ObjectAnimationUsingKeyFrames> </Storyboard> </VisualState> </VisualStateGroup> </VisualStateManager.VisualStateGroups> <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" x:Name="Root"/> <Rectangle x:Name="AltMouseOver" Margin="{TemplateBinding BorderThickness}"/> <Border x:Name="ActiveSelected" BorderBrush="{StaticResource CellItemSelectedBorderBrush}" /> <ContentPresenter VerticalAlignment="{TemplateBinding VerticalContentAlignment}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}"/> <Image Source="{Binding Source=../Resources/red.png}" Width="10" Height="10" VerticalAlignment="Top" HorizontalAlignment="Left" Visibility="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ig:CellControl}}, Converter={StaticResource converterObjectToVisibility}}"/> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style>
Thank you for the feedback.
If you have any questions, please let me know.
Ok perfect I understand and will test your solution later (because this feature is posponed).
Many thanks for you samples and all your time .
Best Regards,
Thank you for the code-snippet you have provided.
In regards to combining a cell style with the conditional formatting, please note that when the conditional formatting is enabled the visual cells are of type ConditionalFormattingCellControl instead of CellControl and it is best for the style to target the new type.
<Style TargetType="ig:ConditionalFormattingCellControl"> <Setter Property="Background" Value="LightGreen" /></Style>
When a column has some rules included to its ConditionalFormatCollection (like the "Weight" column in the sample I provided), there is a Style that is applied by default to the cells of this column. The rest of the columns do not have such style set for their cells. This default style, along with retemplating the whole CellControl can lead to the lack of styling for the cells, since retemplating the cell does not trigger all by-design functionalities of the cell.In order to successfully apply a style to a conditionally formatted cell, you can set the CellStyle property of the column explicitly (both for the existing columns in xaml and when adding them in code-behind):
XAML:
<Style x:Key="conditionalCellStyle" TargetType="ig:ConditionalFormattingCellControl"> <Setter Property="Background" Value="LightGreen" /> </Style> <ig:TextColumn Key="Weight" CellStyle="{StaticResource conditionalCellStyle}"> <ig:TextColumn.ConditionalFormatCollection> ... </ig:TextColumn.ConditionalFormatCollection></ig:TextColumn>
<ig:TextColumn Key="Weight" CellStyle="{StaticResource conditionalCellStyle}"> <ig:TextColumn.ConditionalFormatCollection> ... </ig:TextColumn.ConditionalFormatCollection></ig:TextColumn>
Code-behind:
// Set ConditionalFormatting style explicitly
column.CellStyle = grid.Resources["conditionalCellStyle"] as Style;
I have attached a sample application that demonstrates the approach from above.
The predefined conditional formatting rule instances work with the cell of the value. It seems that you would like to access your DataObject's data in order to perform custom conditional formatting. Since there appear to be some additional logic and implementation that you have used in your application, I can suggest you take a look at the following threads, which you can use as a starting point for implementing a conditional formatting (extending the ConditionalFormattingRuleBase and ConditionalFormattingRuleBaseProxy classes) that suits your functionality:
https://ko.infragistics.com/community/forums/p/53040/275161.aspx#275161https://ko.infragistics.com/community/forums/p/52867/274473.aspx#274473