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
220
Custom format of summary required using IValueConverter
posted

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

Parents
No Data
Reply
  • 27093
    Verified Answer
    posted

    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"/>

    </Style>

     

    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

     

     

     

     

Children