我有一个数据网格,显示扫描计数,逻辑读取等。我已经找到了如何使用转换器和显示计算单个列“扫描计数”的总和。如何为剩余的所有列做同样的事情?总和也显示在扩展器的标题中,所以它是否可以在各自列的底部对齐?
TotalSumConverter.cs
public class TotalSumConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
//First Method
var users = value as IEnumerable<object>;
if (users == null)
return "";
double sum = 0;
foreach (var u in users)
{
sum += ((AggregationTable)u).scanCount;
}
return sum.ToString();
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new System.NotImplementedException();
}
MainWindow.xaml
<Window.Resources>
<local:TotalSumConverter x:Key="sumConverter" />
<Style x:Key="GroupHeaderStyle" TargetType="{x:Type GroupItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type GroupItem}">
<Expander x:Name="exp" IsExpanded="True"
Background="White"
Foreground="Black">
<Expander.Header>
<StackPanel Orientation="Horizontal">
<TextBlock Grid.Column="1" Text="{Binding Path=Name}" Margin="3.5,0" />
<TextBlock Grid.Column="2" Text="Total:" />
<TextBlock Grid.Column="3" Text="{Binding Path=Items, Converter={StaticResource sumConverter}}" TextAlignment="Right" />
</StackPanel>
</Expander.Header>
<ItemsPresenter />
</Expander>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
AggregationTable.cs
class AggregationTable
{
string _table;
double _scanCount;
double _logicalreads;
string _physicalreads;
string _readaheadreads;
string _loblogicalreads;
string _lobphysicalreads;
string _lobreadaheadreads;
public string Table
{
get
{
return _table;
}
set
{
_table = value;
}
}
public double scanCount
{
get
{
return _scanCount;
}
set
{
_scanCount = value;
}
}
public double logicalreads
{
get
{
return _logicalreads;
}
set
{
_logicalreads = value;
}
}