本文整理汇总了C#中ObservableCollection.Take方法的典型用法代码示例。如果您正苦于以下问题:C# ObservableCollection.Take方法的具体用法?C# ObservableCollection.Take怎么用?C# ObservableCollection.Take使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ObservableCollection
的用法示例。
在下文中一共展示了ObservableCollection.Take方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EndRound_IsPlaying_ReturnsResultWithWinnersAndLosers
public void EndRound_IsPlaying_ReturnsResultWithWinnersAndLosers()
{
// ARRANGE
var fakePlayers = new ObservableCollection<IPlayer>() {Substitute.For<IPlayer>(), Substitute.For<IPlayer>()};
FakeGame.End().Returns(fakePlayers.Take(1).ToList());
Target.Players = fakePlayers;
Target.StartNewGame(FakeGame);
Target.StartRound();
var fakeResult = Substitute.For<IRoundResult>();
FakeRoundResultFactory.Invoke(null, null).ReturnsForAnyArgs(fakeResult);
// ACT
var actual = Target.EndRound();
// ASSERT
Assert.AreEqual(fakeResult, actual);
FakeRoundResultFactory.Received().Invoke(Arg.Is<IEnumerable<IPlayer>>(t => t.Contains(fakePlayers[0])), Arg.Is<IEnumerable<IPlayer>>(t => t.Contains(fakePlayers[1])));
}
示例2: OnNavigatedTo
/// <summary>
/// Invoked when this page is about to be displayed in a Frame.
/// </summary>
/// <param name="e">Event data that describes how this page was reached. The Parameter
/// property is typically used to configure the page.</param>
protected async override void OnNavigatedTo(NavigationEventArgs e)
{
XmlNodeList _names = null, _scores = null;
bool fileExists = true;
try
{
StorageFile st = await ApplicationData.Current.LocalFolder.GetFileAsync("score.xml");
dom = await XmlDocument.LoadFromFileAsync(st);
_names = dom.GetElementsByTagName("name");
_scores = dom.GetElementsByTagName("highscore");
}
catch (Exception)
{
fileExists = false;
}
playerTable = new ObservableCollection<Player>();
if (fileExists)
{
for (int i = 0; i < _names.Count; i++)
{
string name = _names.ElementAt(i).InnerText;
int score = Int32.Parse(_scores.ElementAt(i).InnerText);
playerTable.Add(new Player(name, score));
}
}
playerTable = new ObservableCollection<Player>(playerTable.OrderByDescending(player => player.Score));
playerTable = new ObservableCollection<Player>(playerTable.Take(10));
foreach (var elem in playerTable)
{
LeaderBoardControl control = new LeaderBoardControl(elem.Name, elem.Score);
leaderBoardList.Items.Add(control);
}
}
示例3: srv_UserList_GetLowerListDataCompleted
void srv_UserList_GetLowerListDataCompleted(object sender, LotterySrv.GetLowerListDataCompletedEventArgs e)
{
if (e.Result.Count!=0)
{
obLowerData = e.Result as ObservableCollection<LowerListData>;
PageSum.GameScores = obLowerData.Take(18).Sum(p => p.GameScores);
PageSum.EnableScores = obLowerData.Take(18).Sum(p => p.EnableScores);
PageSum.DisableScores = obLowerData.Take(18).Sum(p => p.DisableScores);
TotalSum.GameScores = obLowerData.Sum(p => p.GameScores);
TotalSum.EnableScores = obLowerData.Sum(p => p.EnableScores);
TotalSum.DisableScores = obLowerData.Sum(p => p.DisableScores);
obLowerData.Add(PageSum);
obLowerData.Add(TotalSum);
currentPos = 0;
PagedCollectionView pageView = new PagedCollectionView(obLowerData);
pageView.PageSize = 20;
dpList.PageSize = 20;
dpList.Source = pageView;
dgList.ItemsSource = pageView;
}
gridLoading.Visibility = Visibility.Collapsed;
}
示例4: FilterServicesMethod
private void FilterServicesMethod(object param_)
{
var newDisplayedServices = new ObservableCollection<Service>();
if (string.IsNullOrEmpty(ServicesSearchText))
{
newDisplayedServices = _selectedServices ?? new ObservableCollection<Service>();
}
else
{
foreach (var service in _selectedServices)
{
if (ServicesSearchText == service.Name)
{
newDisplayedServices.Add(service);
}
}
}
_filteredServices = newDisplayedServices;
DisplayedServices = new ObservableCollection<Service>(_filteredServices.Take<Service>(12));
CalculateServicesIndex();
}
示例5: GetDemosHeader
public Task<List<Demo>> GetDemosHeader(List<string> folders)
{
List<Demo> demos = new List<Demo>();
for (int i = 0; i < 20; i++)
{
ObservableCollection<PlayerExtended> players = new ObservableCollection<PlayerExtended>();
Random random = new Random();
ObservableCollection<EntryKillEvent> entryKills = new ObservableCollection<EntryKillEvent>();
for (int indexEntryKill = 0; indexEntryKill < random.Next(5); indexEntryKill++)
{
EntryKillEvent entryKill = new EntryKillEvent(random.Next(7000, 100000))
{
KilledName = "killed" + indexEntryKill,
KilledSteamId = random.Next(8000000),
KilledTeam = Team.Terrorist,
KillerName = "killer" + indexEntryKill,
KillerSteamId = random.Next(800000),
KillerTeam = Team.CounterTerrorist
};
entryKills.Add(entryKill);
}
for (int j = 0; j < 10; j++)
{
PlayerExtended player = new PlayerExtended
{
Name = "player" + (j + 1),
HeadshotCount = random.Next(14),
OnekillCount = random.Next(10, 30),
TwokillCount = random.Next(10, 20),
ThreekillCount = random.Next(0, 10),
FourKillCount = random.Next(0, 5),
FiveKillCount = random.Next(0, 2),
Clutch1V1Count = random.Next(1),
Clutch1V2Count = random.Next(1),
Clutch1V3Count = random.Next(1),
Clutch1V4Count = random.Next(1),
Clutch1V5Count = random.Next(1),
BombDefusedCount = random.Next(0, 2),
BombPlantedCount = random.Next(0, 2),
EntryKills = entryKills,
DeathCount = random.Next(0, 32),
KillsCount = random.Next(30),
AssistCount = random.Next(15),
Score = random.Next(10, 80),
RoundMvpCount = random.Next(6)
};
players.Add(player);
}
ObservableCollection<Round> rounds = new ObservableCollection<Round>();
for (int k = 0; k < 32; k++)
{
Round round = new Round
{
Number = k + 1,
OneKillCount = random.Next(5),
TwoKillCount = random.Next(2),
ThreeKillCount = random.Next(1),
FourKillCount = random.Next(1),
FiveKillCount = random.Next(1),
EquipementValueTeam1 = random.Next(4200, 30000),
EquipementValueTeam2 = random.Next(4200, 30000),
StartMoneyTeam1 = random.Next(4200, 50000),
StartMoneyTeam2 = random.Next(4200, 50000),
Tick = random.Next(7000, 100000)
};
rounds.Add(round);
}
Demo demo = new Demo
{
Id = "de_dust25445648778447878",
Name = "mydemo" + (i + 1) + ".dem",
Tickrate = 128,
MapName = "de_dust2",
ClientName = "localhost",
Hostname = "local",
OneKillCount = random.Next(50, 90),
TwoKillCount = random.Next(20, 50),
ThreeKillCount = random.Next(10),
FourKillCount = random.Next(3),
FiveKillCount = random.Next(1),
Path = "C:\\mydemo.dem",
ScoreTeam1 = 16,
ScoreTeam2 = 6,
Type = "GOTV",
Comment = "comment",
ScoreFirstHalfTeam1 = 10,
ScoreFirstHalfTeam2 = 5,
ScoreSecondHalfTeam1 = 6,
ScoreSecondHalfTeam2 = 1,
Players = players,
PlayersTeam1 = new ObservableCollection<PlayerExtended>(players.Take(5)),
PlayersTeam2 = new ObservableCollection<PlayerExtended>(players.Skip(5).Take(5)),
MostBombPlantedPlayer = players.ElementAt(random.Next(10)),
//.........这里部分代码省略.........
示例6: srv_GameRecord_GetStatReportCompleted
private void srv_GameRecord_GetStatReportCompleted(object sender, GetStatReportCompletedEventArgs e)
{
obStatReport = e.Result;
gridLoading.Visibility = Visibility.Collapsed;
currentPos = 0;
if (e.Result.Count != 0)
{
RTotalSum = new StatReport();
RTotalSum.UserID = "总合计";
RTotalSum.BetMoney = obStatReport.Sum(p => p.BetMoney);
RTotalSum.WinMoney = obStatReport.Sum(p => p.WinMoney);
if (e.Result.Count < 18)
{
obStatReport = e.Result;
RPageSum = new StatReport();
RPageSum.UserID = "本页合计";
RPageSum.BetMoney = obStatReport.Take(18).Sum(p => p.BetMoney);
RPageSum.WinMoney = obStatReport.Take(18).Sum(p => p.WinMoney);
obStatReport.Add(RPageSum);
obStatReport.Add(RTotalSum);
currentPos = 0;
PagedCollectionView pageView = new PagedCollectionView(obStatReport);
pageView.PageSize = 20;
dpList.PageSize = 20;
dpList.Source = pageView;
dgList.ItemsSource = pageView;
}
else
{
int page = int.Parse(Math.Ceiling(double.Parse(e.Result.Count.ToString()) / 18).ToString());
for (int i = 0; i < page; i++)
{
int stayNum = e.Result.Count - (i * 20);
if (stayNum > 18)
{
RPageSum = new StatReport();
RPageSum.UserID = "本页合计";
RPageSum.BetMoney = obStatReport.Skip(i * 20).Take(18).Sum(p => p.BetMoney);
RPageSum.WinMoney = obStatReport.Skip(i * 20).Take(18).Sum(p => p.WinMoney);
obStatReport.Insert(i * 20 + 18, RPageSum);
obStatReport.Insert(i * 20 + 19, RTotalSum);
}
else
{
RPageSum = new StatReport();
RPageSum.UserID = "本页合计";
RPageSum.BetMoney = obStatReport.Skip(i * 20).Take(stayNum).Sum(p => p.BetMoney);
RPageSum.WinMoney = obStatReport.Skip(i * 20).Take(stayNum).Sum(p => p.WinMoney);
obStatReport.Insert(i * 20 + stayNum, RPageSum);
obStatReport.Insert(i * 20 + stayNum + 1, RTotalSum);
}
}
currentPos = 0;
PagedCollectionView pageView = new PagedCollectionView(obStatReport);
pageView.PageSize = 20;
dpList.PageSize = 20;
dpList.Source = pageView;
dgList.ItemsSource = pageView;
}
}
}
示例7: HandleGetCliniciansByLocationCompleted
private void HandleGetCliniciansByLocationCompleted( ReceivedResponses receivedResponses )
{
var response = receivedResponses.Get<GetCliniciansByLocationKeyResponse> ();
var clinicianDtos = new ObservableCollection<StaffNameDto> ( response.Clinicians );
foreach ( var clinicianDto in clinicianDtos.Take ( 8 ) )
{
_navigationService.Navigate (
RegionManager,
TilesRegion,
"ClinicianScheduleTileView",
null,
new[]
{
new KeyValuePair<string, string> ( "ClinicianKey", clinicianDto.Key.ToString () ),
new KeyValuePair<string, string> ( "SelectedDate", SelectedDate.ToShortDateString () )
} );
}
IsLoading = false;
}
示例8: GetImageList
private List<VideoNewShow> GetImageList(ObservableCollection<VideoShowInfo> videoList)
{
return ((from video in videoList.Take(4)
select new VideoNewShow
{
Vid = video.Vid,
Title = video.Title,
Img = video.Img,
Sub_Index = video.Sub_Index,
Flag = videoList.IndexOf(video) == 0 ? "最新" : video.Sub_Index.Substring(4, 2) + "." + video.Sub_Index.Substring(6, 2)
}).OrderByDescending(data => data.Sub_Index)).ToList();
}
示例9: RefreshAsync
/// <summary>
/// Refresh the changeset data asynchronously.
/// </summary>
private async Task RefreshAsync()
{
try
{
var pc = GetService<IPendingChangesExt>();
var currentlyAssociatedWorkItems = pc.WorkItems;
// Set our busy flag and clear the previous data
this.IsBusy = true;
this.RecentWorkItems.Clear();
var workItems = new ObservableCollection<AssociatedWorkItemInfo>();
// Make the server call asynchronously to avoid blocking the UI
await Task.Run(() =>
{
ITeamFoundationContext context = this.CurrentContext;
if (context != null && context.HasCollection && context.HasTeamProject)
{
var vcs = context.TeamProjectCollection.GetService<VersionControlServer>();
if (vcs != null)
{
string path = "$/" + context.TeamProjectName;
foreach (Changeset changeset in vcs.QueryHistory(path, VersionSpec.Latest, 0, RecursionType.Full,
vcs.AuthorizedUser, null, null, 10, false, true))
{
foreach (var wi in changeset.AssociatedWorkItems)
{
if (workItems.All(w => w.Id != wi.Id) && currentlyAssociatedWorkItems.All(w => w.WorkItem.Id != wi.Id))
{
workItems.Add(wi);
}
}
}
}
}
});
// Now back on the UI thread, update the bound collection and section title
this.RecentWorkItems = new ObservableCollection<AssociatedWorkItemInfo>(workItems.Take(5));
this.Title = this.RecentWorkItems.Count > 0 ? String.Format(" {0} ({1})", SectionTitle, this.RecentWorkItems.Count)
: SectionTitle;
}
catch (Exception ex)
{
ShowNotification(ex.Message, NotificationType.Error);
}
finally
{
// Always clear our busy flag when done
this.IsBusy = false;
}
}
示例10: MainWindow_Loaded
void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
albumCollection = new ObservableCollection<AlbumDirectory>();
string recentAlbumsFilePath = Directory.GetCurrentDirectory() + @"\Albums.xml";
if (File.Exists(recentAlbumsFilePath))
{
var albums = Serializer<Albums>.DeserializeFromFile(recentAlbumsFilePath);
this.albumCollection = new ObservableCollection<AlbumDirectory>(albums.AlbumDirectories);
if (albums.TrackList != null && albums.TrackList.Count > 0)
{
this.trackList = new ObservableCollection<Track>(albums.TrackList);
this.currentTrack = this.trackList[0];
var albumD =
this.albumCollection.SingleOrDefault(
x => x != null && x.IsNotNull && x.AlbumNo == StringHelper.Left(this.currentTrack.TrackNo, 4));
this.NavigateToSelectedAlbumAndSong(albumD);
this.BindingToAlbumSelected(albumD);
}
else
{
this.MusicListBox.ItemsSource = albumCollection.Take(12);
}
this.TrackListBox.ItemsSource = this.trackList;
this.AddToCollectionTopAlbumByGenre("Pop");
}
}
示例11: AnalyzeDemo
public Task<Demo> AnalyzeDemo(Demo demo)
{
Random random = new Random();
ObservableCollection<PlayerExtended> players = new ObservableCollection<PlayerExtended>();
for (int i = 0; i < 10; i++)
{
PlayerExtended player = new PlayerExtended
{
Name = "player" + (i + 1),
HeadshotCount = random.Next(14),
OnekillCount = random.Next(10, 30),
TwokillCount = random.Next(10, 20),
ThreekillCount = random.Next(0, 10),
FourKillCount = random.Next(0, 5),
FiveKillCount = random.Next(0, 2),
Clutch1V1Count = random.Next(1),
Clutch1V2Count = random.Next(1),
Clutch1V3Count = random.Next(1),
Clutch1V4Count = random.Next(1),
Clutch1V5Count = random.Next(1),
BombDefusedCount = random.Next(0, 2),
BombPlantedCount = random.Next(0, 2),
DeathCount = random.Next(0, 32),
KillsCount = random.Next(30),
AssistCount = random.Next(15),
Score = random.Next(10, 80),
RoundMvpCount = random.Next(6),
RankNumberNew = 5,
RankNumberOld = 4,
RatingHltv = (float)random.NextDouble(),
SteamId = random.Next(1000, 800000),
IsOverwatchBanned = random.Next(100) < 40,
IsVacBanned = random.Next(100) < 40,
TeamKillCount = random.Next(0, 1),
WinCount = random.Next(10, 687)
};
players.Add(player);
ObservableCollection<EntryKillEvent> entryKills = new ObservableCollection<EntryKillEvent>();
for (int indexEntryKill = 0; indexEntryKill < random.Next(5); indexEntryKill++)
{
EntryKillEvent entryKill = new EntryKillEvent(random.Next(7000, 100000))
{
Killed = players.ElementAt(random.Next(0, 9)),
KilledTeam = Team.Terrorist,
Killer = players.ElementAt(random.Next(0, 9)),
KillerTeam = Team.CounterTerrorist
};
entryKills.Add(entryKill);
}
ObservableCollection<OpenKillEvent> openKills = new ObservableCollection<OpenKillEvent>();
for (int indexOpenKill = 0; indexOpenKill < random.Next(5); indexOpenKill++)
{
OpenKillEvent openKill = new OpenKillEvent(random.Next(7000, 100000))
{
Killed = players.ElementAt(random.Next(0, 9)),
KilledTeam = Team.Terrorist,
Killer = players.ElementAt(random.Next(0, 9)),
KillerTeam = Team.CounterTerrorist
};
openKills.Add(openKill);
}
players.Last().EntryKills = entryKills;
players.Last().OpeningKills = openKills;
}
ObservableCollection<TeamExtended> teams = new ObservableCollection<TeamExtended>
{
new TeamExtended
{
Name = "Team 1",
Players = new ObservableCollection<PlayerExtended>(players.Take(5))
},
new TeamExtended
{
Name = "Team 2",
Players = new ObservableCollection<PlayerExtended>(players.Skip(5).Take(5))
}
};
ObservableCollection<Round> rounds = new ObservableCollection<Round>();
for (int i = 0; i < 32; i++)
{
Round round = new Round
{
Number = i + 1,
OneKillCount = random.Next(5),
TwoKillCount = random.Next(2),
ThreeKillCount = random.Next(1),
FourKillCount = random.Next(1),
FiveKillCount = random.Next(1),
EquipementValueTeam1 = random.Next(4200, 30000),
EquipementValueTeam2 = random.Next(4200, 30000),
StartMoneyTeam1 = random.Next(4200, 50000),
StartMoneyTeam2 = random.Next(4200, 50000),
Tick = random.Next(7000, 100000),
//.........这里部分代码省略.........
示例12: AnalyzeDemo
public Task<Demo> AnalyzeDemo(Demo demo, CancellationToken token)
{
Random random = new Random();
ObservableCollection<PlayerExtended> players = new ObservableCollection<PlayerExtended>();
for (int i = 0; i < 10; i++)
{
PlayerExtended player = new PlayerExtended
{
Name = "player" + (i + 1),
HeadshotCount = random.Next(14),
OnekillCount = random.Next(10, 30),
TwokillCount = random.Next(10, 20),
ThreekillCount = random.Next(0, 10),
FourKillCount = random.Next(0, 5),
FiveKillCount = random.Next(0, 2),
Clutch1V1Count = random.Next(1),
Clutch1V2Count = random.Next(1),
Clutch1V3Count = random.Next(1),
Clutch1V4Count = random.Next(1),
Clutch1V5Count = random.Next(1),
BombDefusedCount = random.Next(0, 2),
BombPlantedCount = random.Next(0, 2),
DeathCount = random.Next(0, 32),
KillsCount = random.Next(30),
AssistCount = random.Next(15),
Score = random.Next(10, 80),
RoundMvpCount = random.Next(6),
RankNumberNew = 5,
RankNumberOld = 4,
RatingHltv = (float)random.NextDouble(),
SteamId = random.Next(1000, 800000),
IsOverwatchBanned = random.Next(100) < 40,
IsVacBanned = random.Next(100) < 40,
TeamKillCount = random.Next(0, 1),
WinCount = random.Next(10, 687),
MolotovThrownCount = random.Next(0, 10),
DecoyThrownCount = random.Next(0, 10),
IncendiaryThrownCount = random.Next(20),
SmokeThrownCount = random.Next(20),
FlashbangThrownCount = random.Next(20),
HeGrenadeThrownCount = random.Next(20),
BombExplodedCount = random.Next(5),
AvatarUrl = string.Empty,
ClutchCount = random.Next(5),
ClutchLostCount = random.Next(5),
KillDeathRatio = (decimal)random.NextDouble(),
MatchCount = random.Next(100),
OpponentClutchCount = random.Next(5),
RoundPlayedCount = random.Next(100)
};
players.Add(player);
}
TeamExtended teamT = new TeamExtended
{
Name = "Team 1",
Players = new ObservableCollection<PlayerExtended>(players.Take(5))
};
TeamExtended teamCt = new TeamExtended
{
Name = "Team 2",
Players = new ObservableCollection<PlayerExtended>(players.Skip(5).Take(5))
};
ObservableCollection<Round> rounds = new ObservableCollection<Round>();
for (int i = 0; i < 32; i++)
{
ObservableCollection<KillEvent> kills = new ObservableCollection<KillEvent>();
for (int j = 0; j < random.Next(1, 9); j++)
{
PlayerExtended killer = players.ElementAt(random.Next(9));
PlayerExtended killed = players.ElementAt(random.Next(9));
kills.Add(new KillEvent(random.Next(1, 10000), random.Next(1, 100))
{
KillerName = killer.Name,
KillerSteamId = killer.SteamId,
KillerSide = killer.Side,
KilledName = killed.Name,
KilledSteamId = killed.SteamId,
KilledSide = killed.Side,
RoundNumber = i,
Weapon = Weapon.WeaponList.ElementAt(random.Next(44))
});
}
// generate open / entry kills for this round
Round round = new Round
{
Number = i + 1,
OneKillCount = random.Next(5),
TwoKillCount = random.Next(2),
ThreeKillCount = random.Next(1),
FourKillCount = random.Next(1),
FiveKillCount = random.Next(1),
EquipementValueTeam1 = random.Next(4200, 30000),
EquipementValueTeam2 = random.Next(4200, 30000),
StartMoneyTeam1 = random.Next(4200, 50000),
StartMoneyTeam2 = random.Next(4200, 50000),
Tick = random.Next(7000, 100000),
//.........这里部分代码省略.........