Search code examples
wpfxamluser-interfaceinfragisticsxamdatagrid

How to add contents of 2 fields to get summary in XAML code?


I would like to know how to get the column summary in XAML code. I'm able to get the row summaries using the code mentioned in attachment or image. But I do not know how to add contents from "a1" ,"b1" and "c1" to get the "Summary" in XAML code only without using code-behind . I'm using Infragistics xamDataGrid

please refer this


Solution

  • You need MultiBinding and MultiValueConverter. Below example calculates sum of Num1 and Num2 properties and shows their Sum.

                <DataGridTextColumn Header="Sum">
                    <DataGridTextColumn.Binding>
                        <MultiBinding Converter="{StaticResource SumCnvKey}">
                            <Binding Path="Num1"/>
                            <Binding Path="Num2"/>
                        </MultiBinding>
                    </DataGridTextColumn.Binding>
                </DataGridTextColumn>
    

    Converter:

    public class SumConverter : IMultiValueConverter
    {
        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (values[0] != DependencyProperty.UnsetValue && values[1] != DependencyProperty.UnsetValue && values[2] != DependencyProperty.UnsetValue)
    
                return ((int)values[0] + (int)values[1]).ToString();
    
            else
                return DependencyProperty.UnsetValue;
        }
    
        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }