Standardowa kontrolka chyba nie ma takiej funkcjonalności. Ale coś takiego chciałeś osiągnąć?:
<Grid>
<ListView ItemsSource="{Binding ListViewCollection}" Margin="0,0,0,69">
<ListView.View>
<GridView>
<GridViewColumn Width="140" Header="Name"
DisplayMemberBinding="{Binding Name}" />
<GridViewColumn Width="140" Header="Number"
DisplayMemberBinding="{Binding Number}" />
</GridView>
</ListView.View>
</ListView>
<Button Margin="0,250,272,0" Content="Sumuj" Click="SumClick"></Button>
<Button Margin="250,250,22,0" Content="Wszystko" Click="AllClick"/>
</Grid>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
DataContext = this;
FooCollection = new ObservableCollection<Foo>
{
new Foo {Name = "A", Number = 1},
new Foo {Name = "A", Number = 1},
new Foo {Name = "B", Number = 1},
new Foo {Name = "B", Number = 1},
new Foo {Name = "A", Number = 1}
};
ListViewCollection = new ObservableCollection<Foo>(FooCollection);
}
public ObservableCollection<Foo> FooCollection { get; set; }
public ObservableCollection<Foo> ListViewCollection { get; set; }
private void SumClick(object sender, RoutedEventArgs e)
{
var tmpCollection =
ListViewCollection.GroupBy(x => x.Name)
.Select(x => new Foo {Name = x.Key, Number = x.Sum(s => s.Number)})
.ToList();
ListViewCollection.Clear();
foreach (var foo in tmpCollection)
{
ListViewCollection.Add(foo);
}
}
private void AllClick(object sender, RoutedEventArgs e)
{
ListViewCollection.Clear();
foreach (var foo in FooCollection)
{
ListViewCollection.Add(foo);
}
}
}
public class Foo
{
public string Name { get; set; }
public int Number { get; set; }
}