-1

I'm kinda new to Lambda many things work already but right now I'm getting to the limit of my understanding.

I have a WPF App, where I want to show some stats that I recorded into a Json file.

The file looks like this:

Date, Name, Position, Region

Now I want to add all those Information into a ListView

The ListView looks more or less like this:

<ListView x:Name="lbtNames" FontSize="16" HorizontalContentAlignment="Left" Margin="24,122,207,19"> <ListView.View> <GridView> <GridViewColumn Header="Hero:" Width="120" DisplayMemberBinding="{Binding Name}"></GridViewColumn> <GridViewColumn Header="Count: " Width="50" DisplayMemberBinding="{Binding Count}"></GridViewColumn> </GridView> </ListView.View> </ListView> 

And the Code behind:

var query = _recordList .GroupBy(x => x.Name, (y, z) => new { Name= y, Count = z.Count() }) .OrderByDescending(o => o.Count); lbtNames.ItemsSource = query; 

So far so easy now I also would like to add some more Information like Average Position and maybe a small graph that shows over time the positions, well this will be made seperatly but to my ListView I would add the Column Average Position somehow, is it possible to add more to my Lambda statement?

0

1 Answer 1

3

Yes, you just make it a multi line statement inside a code block, with a return

Your this:

.GroupBy(x => x.Name, (y, z) => new { Name= y, Count = z.Count() }) 

Is like this:

.GroupBy(x => x.Name, (y, z) => { return new { Name= y, Count = z.Count() }; }) 

So you can:

.GroupBy(x => x.Name, (y, z) => { int i = SomeCalc(); var r = new { Name= y, Count = z.Count(), Result = i }; return r; }) 
Sign up to request clarification or add additional context in comments.

2 Comments

but isnt r.Name read only? and can I also add another column like AvgPosition where I just do something like Position/Count where Name = Name
You can add AvgPosition certainly, and you could calculate it yourself, but I'm not sure why you need to calc it yourself when LINQ has an Average<T>()..

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.