Hi
I have an "IValueConverter" format cell contents in a data bound grid - it works a treat thanks to Petar Monov. My next challenge is to apply the same formatting to the row summaries - re-using the same IValueConverter (I hope!).
Petar suggested this XAML for the cell contents .. but I can't get the syntax for the summary:
<igDP:Field Name="Distance" >
<igDP:Field.Settings>
<igDP:FieldSettings >
<igDP:FieldSettings.EditorStyle>
<Style TargetType="{x:Type igEditors:XamNumericEditor}">
<Setter Property="ValueToDisplayTextConverter" Value="{StaticResource FormatDistance}" />
</Style>
</igDP:FieldSettings.EditorStyle>
</igDP:FieldSettings>
</igDP:Field.Settings>
</igDP:Field>
My summary will be a "sum" of the "Distance" column. I can get the summary to appear, but it is not formatted using my custom formatter.
Any ideas would be appreciated.
Regards
Gary
Hi Gary,
I have been looking into this for you and have found a way you can achieve it. This is indeed a bit more complex since the XamDataGrid does not provide the means for conditionally formatting summaries and formatting each Field’s summaries differently. This is why I managed to do it using a keyless style targeting the SummaryResult class which actually displays underneath your column. In order to not lose any of the built-in functionality I have copied the original template from the DefaultStyles folder:
<Style TargetType="{x:Type igDP:SummaryResultPresenter}">
<Setter Property="Padding" Value="1,1"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type igDP:SummaryResultPresenter}">
<Border
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="1"
Padding="{TemplateBinding Padding}"
ToolTip="{Binding Path=SummaryResult.ToolTipResolved, RelativeSource={RelativeSource TemplatedParent}}">
<!--<TextBlock Text="{Binding Path=SummaryResult.DisplayTextAsync, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}"/>-->
<TextBlock Text="{Binding Path=SummaryResult, Converter={StaticResource SummaryFormatCON}, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="Margin" Value="0,0,0,2"/>
by adding a converter to the TextBlock displaying the summary and changing its binding path so that I can access the actual object in the Convert method.
Here is the code snippet I concocted in order to get the formatting for all summaries (not only “Sum”). I am performing some checks one of which is for the Field that is being summarized since this style would apply to all the summaries in the XamDataGrid and you wouldn’t want all your double summaries to have “m”, “km”. I also included some additional coding for the Count summary since it doesn’t seem appropriate to be formatted:
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value.GetType() == typeof(SummaryResult) && value != null)
SummaryResult sr = (value as SummaryResult);
double temp;
if (sr.SourceField.Name == "IntBarColumn") //this is my Field's name... change it :]
if (double.TryParse(sr.Value.ToString(), out temp))
if (sr.SummaryDefinition.Calculator.DisplayName != "Count")
if (temp < 1000)
return sr.DisplayText + " m";
}
else
return sr.DisplayText.Replace(temp.ToString("#,###.00"), (temp / 1000).ToString()) + " km";
return sr.DisplayText.ToString();
return value;
Please let me know if I can be of any further assistance, or if you can use any clarifications on the matter.
Sincerely,
Petar Monov
Developer Support Engineer
Infragistics Bulgaria
www.infragistics.com/support
Hi Petar
Yes - that worked brilliantly. It took me a while to work out where to put the <Style> code (I'm new to WPF), but now I have the idea - it goes under <Window.Resrouces> for anyone else reading this and wondering.
Thanks for the tip where you used the DataPresenter XAML from the DefaultStyles folder - that's a great reference point for the future as a place to look.
I've marked this as the answer - let me know if that didn't work. I did mark my last post to you as answered and it didn't work!
Thanks. It is verified. Since you say you are new to WPF, I just wanted to point you out that putting the style in Windows.Resource will work as well as putting it within the resources of any of the XamDataGrid’s ancestor elements of the visual tree. Being set there it would affect all the XamDataGrid’s you have on that Window, but if you want to affect only a specific one you can move it to XamDataGrid.Resources.
Hope this is useful.
Best regards Petar.
Hi Petar,
MY requirement is similar to this. However columns and colors are set from user window.
It means I want to let the client use/change color for different columns with different colors.
Can you provide me the code behind and XAML for the same ?
Thanks in advance,
Vinayak