15.02.2015 Views

C# 4 and .NET 4

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

DataGrid ❘ 1067<br />

}<br />

{<br />

}<br />

return new Lazy(() =><br />

{<br />

return from rr in F1DataContext.Data.RaceResults<br />

where rr.Race.Date == this.Date<br />

select new F1RaceResult<br />

{<br />

Position = rr.Position,<br />

Racer = rr.Racer.Firstname + " " +<br />

rr.Racer.Lastname,<br />

Car = rr.Team.Name<br />

};<br />

});<br />

}<br />

code snippet Formula1Demo/F1Race.cs<br />

The final class of the hierarchy is F1RaceResult, which is a simple data holder for Position, Racer,<br />

<strong>and</strong> Car:<br />

public class F1RaceResult<br />

{<br />

public int Position { get; set; }<br />

public string Racer { get; set; }<br />

public string Car { get; set; }<br />

}<br />

code snippet Formula1Demo/Championship.cs<br />

When you run the application, you can see at first all the years of the championships in the tree view.<br />

Because of binding, the next level is already<br />

accessed — every Championship object<br />

already has the F1Race objects associated.<br />

The user doesn’t need to wait for the first level<br />

after the year or an open year with the default<br />

look of a small triangle. As you can see in<br />

Figure 36-14, the year 1984 is open. As soon as<br />

the user clicks on a year to see the second-level<br />

binding, the third level is done <strong>and</strong> the race<br />

results are retrieved.<br />

Of course you can also customize the TreeView<br />

control <strong>and</strong> define different styles for the<br />

complete template or the items in the view.<br />

daTagrid<br />

Prior to .<strong>NET</strong> 4, a DataGrid control was missing<br />

with WPF. Now it’s here! With the DataGrid<br />

control, information is displayed within rows <strong>and</strong><br />

columns, <strong>and</strong> can also be edited.<br />

figure 36-14<br />

The DataGrid control is an ItemsControl <strong>and</strong> defines the ItemsSource property that is bound to a<br />

collection. The XAML code of this user interface also defines two RepeatButton controls that are used for<br />

paging functionality. Instead of loading all the race information at once, paging is used so users can step<br />

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!