public GamePage() { Type = PageType.Game; _levelDataRepository = new LevelDataRepository(); _randomizer = new Random(); _worldDataRepository = new WorldDataRepository(); _boardContainer = new Container(); AddChild(_boardContainer); _shardContainer = new Container(); AddChild(_shardContainer); }
public HomePageViewModel() { var worldRepository = new WorldDataRepository(); Data = new ObservableCollection <DataItem>(); ItemsSource = new ObservableCollection <CountryItem>(); worldRepository.GetCountries().ContinueWith(list => { Countries = list.Result; var dataItems = new ObservableCollection <DataItem>(); foreach (var item in Countries) { var countryItem = new CountryItem { Name = item.Name, Change = item.Chg1Y, IsChangePositive = item.IsChangePositive }; double val = 0.0; double.TryParse(item.LifeExpectancy, out val); countryItem.LifeExpectancy = val; ItemsSource.Add(countryItem); } foreach (var region in worldRepository.CountriesByRegion) { var dataItem = new DataItem { Label = region.Key, Level = region.Value.Sum(x => x.Level.ToDouble()) }; dataItems.Add(dataItem); } WorldPopulation = dataItems.Sum(l => l.Level * 1000).ToString("#,##0,,,.B", CultureInfo.InvariantCulture); LifeExpectancy = ItemsSource.Average(x => x.LifeExpectancy).ToString("00.00", CultureInfo.InvariantCulture); Data = dataItems; }); }