I am defining the following CellValuePresenter style
<Style x:Key="CellColorStyle" TargetType="{x:Type igWPF:CellValuePresenter}"><!-- Template combines icon set by a separate converter and Text into the same cell -->
<Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type igWPF:CellValuePresenter}"> <StackPanel Orientation="Horizontal"> <Image Source="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Value, Converter={StaticResource StatusIconConverter}}" Width="16" Height="16" Margin="5" /> <TextBlock VerticalAlignment="Center" HorizontalAlignment="Left" Text="{Binding RelativeSource={RelativeSource AncestorType={x:Type igWPF:CellValuePresenter}}, Path=Value}"/> </StackPanel> </ControlTemplate> </Setter.Value> </Setter>
<Setter Property="BorderBrush" Value="Black"/> <Setter Property="BorderThickness" Value="2,0,2,0"/> </Style>
Style is set for one of the Fields in the grid. For whatever reason the column separators between this cells in that column and the adjacent column have gone missing. I attempted to explicitely add the BorderBrush and Borderthickness but these have not helped. Any idea how to restore the separators? Thanks.
Hello Andre,
Thank you for your post.
I have been looking into your question and the reason for the missing separator is that you are overriding the default template of the CellValuePresenter. In order to avoid this appearance, you can use ContentTemplate instead. I have created short sample project that show how you can implement my suggestion.
Please let me know if you require any further assistance regarding this matter.
Thanks Zhivko but I noticed another problem. The problem is that in the style I am also coloring the text block (setting foreground color). It worked just fine with the Style I posted above but it stopped when I switched to ContentTemplate solution you suggested. The color is applied to every other row and setting AlternateRow forecolor does not seem to work. Here is my complete style with your suggestion:
<Style x:Key="CellColorStyle" TargetType="{x:Type igWPF:CellValuePresenter}"> <!-- Setter for foreground text color using appropriate converter --> <Setter Property="Foreground" Value="{Binding Path=DataItem.TradeDate, Converter={StaticResource PastDueToColorConverter}}"/>
<Setter Property="ContentTemplate"> <Setter.Value> <DataTemplate> <StackPanel Orientation="Horizontal"> <Image Source="{Binding RelativeSource={RelativeSource AncestorType={x:Type igWPF:CellValuePresenter}}, Path=Value, Converter={StaticResource StatusIconConverter}}" Width="16" Height="16" Margin="5" /> <TextBlock VerticalAlignment="Center" Text="{Binding RelativeSource={RelativeSource AncestorType={x:Type igWPF:CellValuePresenter}}, Path=Value}"/> </StackPanel> </DataTemplate> </Setter.Value> </Setter>
</Style>
I also have the following style defined in the same file - it sets appropriate fore color for all CellValuePresenter cells except the cells using the style CellColorStyle. Can I use it to set the CellColorStyle fore color as well? Thanks.
<Style TargetType="{x:Type igWPF:CellValuePresenter}"> <!--To color --> <Setter Property="Foreground" Value="{Binding Path=DataItem.TradeDate, Converter={StaticResource PastDueToColorConverter}}"/> <!--To alternate color --> <Setter Property="ForegroundAlternateStyle"> <Setter.Value> <Style> <Setter Property="TextElement.Foreground" Value="{Binding Path=DataItem.TradeDate, Converter={StaticResource PastDueToColorConverter}}" /> </Style> </Setter.Value> </Setter> <!--To color on cell activation --> <Setter Property="ForegroundActiveStyle"> <Setter.Value> <Style> <Setter Property="TextElement.Foreground" Value="{Binding Path=DataItem.TradeDate, Converter={StaticResource PastDueToColorConverter}}" /> </Style> </Setter.Value> </Setter> <!--To color on cell hover--> <Setter Property="ForegroundHoverStyle"> <Setter.Value> <Style> <Setter Property="TextElement.Foreground" Value="{Binding Path=DataItem.TradeDate, Converter={StaticResource PastDueToColorConverter}}" /> </Style> </Setter.Value> </Setter> <!--To color on cell selection (no hover)--> <Setter Property="ForegroundSelectedStyle"> <Setter.Value> <Style> <Setter Property="TextElement.Foreground" Value="{Binding Path=DataItem.TradeDate, Converter={StaticResource PastDueToColorConverter}}" /> </Style> </Setter.Value> </Setter> <Style.Triggers> <!--To color on record selection--> <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=Record.IsSelected}" Value="True"> <Setter Property="ForegroundStyle"> <Setter.Value> <Style> <Setter Property="TextElement.Foreground" Value="{Binding Path=DataItem.TradeDate, Converter={StaticResource PastDueToColorConverter}}" /> </Style> </Setter.Value> </Setter> </DataTrigger> <!--To color on record hover (no selection) --> <Trigger Property="IsMouseOverRecord" Value="True"> <Setter Property="ForegroundStyle"> <Setter.Value> <Style> <Setter Property="TextElement.Foreground" Value="{Binding Path=DataItem.TradeDate, Converter={StaticResource PastDueToColorConverter}}"/> </Style> </Setter.Value> </Setter> </Trigger> </Style.Triggers> </Style>
Thank you for your feedback.
I have been looking into your issue and I am not sure that I understand correctly what you are trying to achieve. If you would like each cell of the field with CellColorStyle to be colored equally, what I can suggest is to set the foreground property of the TextBlock in the CellColorStyle to the color you wish. I modified my sample application in order to show you how you can implement this suggestion.
Zhivko, what I am trying to achieve is have the following:
1. Ability to set the color for an entire row in the grid based on the value returned by PastDueToColorConverter
2. Ability to add an image (in addition to text) to one of the cells in the grid.
So my approach has been to define as style just for the cell with an image and text (and set the color the way that I want using converter) - that style combines the image (returned by another converter) and text of the appropriate color in the same stack. Also, have another Style targeting CellValuePresenter that will set color in all modes (mouse over, highlighted etc) for all other cells in the row.
Although messy, my code works aside from the column separator missing. When I switched from defining cell Template to ContentTemplate for some reason alternate color and mouse hover, selected row fore colors disappeared.
Perhaps its not the best approach - can you provide a sample where your style is modified to add an image? Its very important that all modes (mouse hover, alternate color, selected and others) are supported for a colored row. Thanks!
Hello,
I am just checking if you require any further assistance on the matter.
I have been looking into your issue and have modified the sample application, that Zhivko has provided in his latest post.
In order to have all of the styles for the cells where there is an Image I can suggest changing the default style of the CellValuePresenter. The default styles for our controls can be found on the following location, when you install our controls: C:\Program Files (x86)\Infragistics\2015.2\WPF\DefaultStyles.
You can insert the image right before the ContentPresenter, that would show the value of the cell. Then the Field separator, that you see is called "MainBorder" and can be found in the ControlTemplate of the CellValuePresenter. In order for it to be visible you can set its properties as follows:
<Border
x:Name="MainBorder"
CornerRadius="0,0,0,0"
BorderThickness="0,0,1,0"
BorderBrush="#FFEDEDED"
Background="Transparent"/>
Please find the attached sample application and feel free to let me know if you have any further questions on this matter.