本文整理汇总了C#中ObservableCollection.Average方法的典型用法代码示例。如果您正苦于以下问题:C# ObservableCollection.Average方法的具体用法?C# ObservableCollection.Average怎么用?C# ObservableCollection.Average使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ObservableCollection
的用法示例。
在下文中一共展示了ObservableCollection.Average方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HomePageViewModel
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;
});
}
示例2: client_GetMapDataCompleted
void client_GetMapDataCompleted(object sender, GetMapDataCompletedEventArgs e)
{
if (e.Error == null)
{
m_mapDataList = new ObservableCollection<MapData>();
m_mapDataList = e.Result;
double avgLongitude = Convert.ToDouble(m_mapDataList.Average(m => m.Longitude));
double avgLatitude = Convert.ToDouble(m_mapDataList.Average(m => m.Latitude));
foreach (MapData mapData in m_mapDataList)
{
m_pushPinButton = new Button();
m_toolTip = new ToolTip();
m_toolTip.DataContext = mapData;
m_toolTip.Template = Application.Current.Resources["MapToolTipTemplate"] as ControlTemplate;
ToolTipService.SetToolTip(m_pushPinButton, m_toolTip);
m_pushPinButton.Content = mapData.CompanyMapAcronym;
if (mapData.DeviceType == "Device")
m_pushPinButton.Template = Application.Current.Resources["BluePushPinButtonTemplate"] as ControlTemplate;
else if (mapData.Desired == true)
m_pushPinButton.Template = Application.Current.Resources["YellowPushPinButtonTemplate"] as ControlTemplate;
else
m_pushPinButton.Template = Application.Current.Resources["WhitePushPinButtonTemplate"] as ControlTemplate;
//pushPinButton.SetValue(MapLayer.MapPositionProperty, new Location(Convert.ToDouble(mapData.Latitude), Convert.ToDouble(mapData.Longitude)));
//pushPinButton.SetValue(MapLayer.MapPositionMethodProperty, PositionMethod.Center);
(VirtualEarthPlanningMap.FindName("PushpinLayer") as MapLayer).AddChild(m_pushPinButton, new Location(Convert.ToDouble(mapData.Latitude), Convert.ToDouble(mapData.Longitude)));
}
VirtualEarthPlanningMap.Center = new Location(avgLatitude, avgLongitude);
}
else
{
SystemMessages sm;
if (e.Error is FaultException<CustomServiceFault>)
{
FaultException<CustomServiceFault> fault = e.Error as FaultException<CustomServiceFault>;
sm = new SystemMessages(new Message() { UserMessage = fault.Detail.UserMessage, SystemMessage = fault.Detail.SystemMessage, UserMessageType = MessageType.Error },
ButtonType.OkOnly);
}
else
sm = new SystemMessages(new Message() { UserMessage = "Failed to Retrieve Planning Map Data", SystemMessage = e.Error.Message, UserMessageType = MessageType.Error },
ButtonType.OkOnly);
sm.ShowPopup();
}
}