本文整理汇总了C#中ObservableCollection.Sort方法的典型用法代码示例。如果您正苦于以下问题:C# ObservableCollection.Sort方法的具体用法?C# ObservableCollection.Sort怎么用?C# ObservableCollection.Sort使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ObservableCollection
的用法示例。
在下文中一共展示了ObservableCollection.Sort方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: sorting_members_directly
public void sorting_members_directly()
{
List<int> sortedCol = new List<int>() { 1, 2, 3, 4 };
ObservableCollection<int> col = new ObservableCollection<int>() { 1, 3, 2, 4 };
col.Sort(x => x);
Assert.IsTrue(CollectionUtils.ContentEqual(col, sortedCol));
}
示例2: sorting_members_by_their_fields
public void sorting_members_by_their_fields()
{
var v1 = new DataHolder(1);
var v2 = new DataHolder(2);
var v3 = new DataHolder(3);
var v4 = new DataHolder(4);
var v5 = new DataHolder(5);
List<DataHolder> sortedCol = new List<DataHolder>() { v1, v2, v3, v4, v5 };
ObservableCollection<DataHolder> col = new ObservableCollection<DataHolder>() { v5, v1, v3, v2, v4 };
col.Sort(x => x.X);
Assert.IsTrue(CollectionUtils.ContentEqual(col, sortedCol));
}
示例3: MainWindowViewModel
public MainWindowViewModel(ObservableCollection<FavShowData> shows)
{
_tvShows = new ObservableCollection<ShowTileViewModel>();
shows.CollectionChanged += update_source;
foreach (FavShowData favShowData in shows)
{
var x = new ShowTileViewModel(favShowData);
_tvShows.Add(x);
}
if (Settings.Instance.SortShowsAlphabetically)
_tvShows.Sort(ShowComparer);
}
示例4: sorting_members_by_their_nullable_fields
public void sorting_members_by_their_nullable_fields()
{
var v1 = new DataHolder((DateTime?)null);
var v2 = new DataHolder(DateTime.Now.AddHours(1));
var v3 = new DataHolder(DateTime.Now.AddHours(2));
var v4 = new DataHolder(DateTime.Now.AddHours(3));
var v5 = new DataHolder(DateTime.Now.AddHours(4));
List<DataHolder> sortedCol = new List<DataHolder>() { v1, v2, v3, v4, v5 };
ObservableCollection<DataHolder> col = new ObservableCollection<DataHolder>() { v5, v1, v3, v2, v4 };
Func<DateTime?, DateTime?, int> comparer = (x, y) =>
{
if (x == null)
return (y == null) ? 0 : -1;
if (y == null)
return 1;
return (x.Value == y.Value) ? 0 : (x.Value > y.Value) ? 1 : 0;
};
col.Sort(x => x.D);
Assert.IsTrue(CollectionUtils.ContentEqual(col, sortedCol));
}
示例5: LoadSubtitlesAsync
/// <summary>
/// Get the movie's subtitles according to a language
/// </summary>
/// <param name="movie">The movie of which to retrieve its subtitles</param>
/// <param name="ct">Cancellation token</param>
public async Task LoadSubtitlesAsync(MovieFull movie,
CancellationToken ct)
{
var restClient = new RestClient(Constants.YifySubtitlesApi);
var request = new RestRequest("/{segment}", Method.GET);
request.AddUrlSegment("segment", movie.ImdbCode);
var response = await restClient.ExecuteGetTaskAsync(request, ct);
if (response.ErrorException != null)
{
Logger.Error(
$"Error while getting the movie's subtitles of {movie.Title}: {response.ErrorException.Message}");
Messenger.Default.Send(new ManageExceptionMessage(new Exception(response.ErrorException.Message)));
}
var wrapper =
await Task.Run(() => JsonConvert.DeserializeObject<SubtitlesWrapperDeserialized>(response.Content), ct);
var subtitles = new ObservableCollection<Subtitle>();
Dictionary<string, List<SubtitleDeserialized>> movieSubtitles;
if (wrapper.Subtitles.TryGetValue(movie.ImdbCode, out movieSubtitles))
{
foreach (var subtitle in movieSubtitles)
{
var sub = subtitle.Value.Aggregate((sub1, sub2) => sub1.Rating > sub2.Rating ? sub1 : sub2);
subtitles.Add(new Subtitle
{
Id = sub.Id,
Language = new CustomLanguage
{
Culture = string.Empty,
EnglishName = subtitle.Key,
LocalizedName = string.Empty
},
Hi = sub.Hi,
Rating = sub.Rating,
Url = sub.Url
});
}
}
subtitles.Sort();
movie.AvailableSubtitles = subtitles;
}
示例6: updatePlayerAndMetricStats
/// <summary>Calculates the player and metric stats and updates the corresponding tabs.</summary>
private void updatePlayerAndMetricStats()
{
_psrList = new ObservableCollection<PlayerStatsRow>();
_plPSRList = new ObservableCollection<PlayerStatsRow>();
var players = _pst.Where(pair => pair.Value.TeamF == _curTeam && !pair.Value.IsHidden);
foreach (var pl in players)
{
_psrList.Add(new PlayerStatsRow(pl.Value, false));
_plPSRList.Add(new PlayerStatsRow(pl.Value, true));
}
_psrList.Sort((row1, row2) => String.CompareOrdinal(row1.LastName, row2.LastName));
_plPSRList.Sort((row1, row2) => String.CompareOrdinal(row1.LastName, row2.LastName));
dgvPlayerStats.ItemsSource = rbPlayerStatsSeason.IsChecked == true ? _psrList : _plPSRList;
dgvMetricStats.ItemsSource = dgvPlayerStats.ItemsSource;
dgvTeamRoster.ItemsSource = _psrList;
dgvTeamRoster.CanUserAddRows = false;
}
示例7: Window_Loaded
private void Window_Loaded(object sender, RoutedEventArgs e)
{
_headCollection = GenericRepository.GetAllObservableCollection<Y_NORM_PROFILE_HEAD>();
_headCollection.Sort(y => y.ID);
profileHeadGridControl.ItemsSource = _headCollection;
profileHeadGridControl.View.PreviewMouseDoubleClick += View_PreviewMouseDoubleClick;
profileDetailgridControl.View.PreviewMouseDoubleClick += View_DetailPreviewMouseDoubleClick;
profileHeadGridControl.View.FocusedRowChanged += View_FocusedRowChanged;
InitializeMenuButtons();
}
示例8: window_Loaded
private void window_Loaded(object sender, EventArgs e)
{
txbAwayTeam.Text = _tst[_t1ID].DisplayName;
txbHomeTeam.Text = _tst[_t2ID].DisplayName;
AwayPoints = _bse.BS.PTS1;
HomePoints = _bse.BS.PTS2;
CurrentPeriod = 1;
resetTimeLeft();
_timeLeftTimer = new DispatcherTimer { Interval = new TimeSpan(0, 0, 0, 0, 50) };
_timeLeftTimer.Tick += _timeLeftTimer_Tick;
resetShotClock();
_shotClockTimer = new DispatcherTimer { Interval = new TimeSpan(0, 0, 0, 0, 50) };
_shotClockTimer.Tick += _shotClockTimer_Tick;
var awayPlayersIDs = _bse.PBSList.Where(pbs => pbs.TeamID == _t1ID).Select(pbs => pbs.PlayerID).ToList();
AwaySubs = new ObservableCollection<PlayerStats>();
awayPlayersIDs.ForEach(id => AwaySubs.Add(_pst[id]));
AwaySubs.Sort((ps1, ps2) => String.Compare(ps1.FullName, ps2.FullName, StringComparison.CurrentCultureIgnoreCase));
lstAwaySubs.ItemsSource = AwaySubs;
AwayActive = new ObservableCollection<PlayerStats>();
lstAwayActive.ItemsSource = AwayActive;
var homePlayersIDs = _bse.PBSList.Where(pbs => pbs.TeamID == _t2ID).Select(pbs => pbs.PlayerID).ToList();
HomeSubs = new ObservableCollection<PlayerStats>();
homePlayersIDs.ForEach(id => HomeSubs.Add(_pst[id]));
HomeSubs.Sort((ps1, ps2) => String.Compare(ps1.FullName, ps2.FullName, StringComparison.CurrentCultureIgnoreCase));
lstHomeSubs.ItemsSource = HomeSubs;
HomeActive = new ObservableCollection<PlayerStats>();
lstHomeActive.ItemsSource = HomeActive;
PlayersComboList = new ObservableCollection<ComboBoxItemWithIsEnabled>();
PlayersComboList2 = new ObservableCollection<ComboBoxItemWithIsEnabled>();
cmbEventType.ItemsSource = PlayByPlayEntry.EventTypes.Values;
cmbEventType.SelectedIndex = 2;
cmbShotOrigin.ItemsSource = ShotEntry.ShotOrigins.Values;
cmbShotType.ItemsSource = ShotEntry.ShotTypes.Values;
cmbPlayer1.ItemsSource = PlayersComboList;
cmbPlayer2.ItemsSource = PlayersComboList2;
if (Plays == null)
{
Plays = new ObservableCollection<PlayByPlayEntry>();
}
dgEvents.ItemsSource = Plays;
#if DEBUG
for (var i = 0; i < 5; i++)
{
HomeActive.Add(HomeSubs[0]);
HomeSubs.RemoveAt(0);
AwayActive.Add(AwaySubs[0]);
AwaySubs.RemoveAt(0);
}
sortPlayerLists();
#endif
}
示例9: updatePlayerAndMetricStats
/// <summary>
/// Calculates the player and metric stats and updates the corresponding tabs.
/// </summary>
private void updatePlayerAndMetricStats()
{
_psrList = new ObservableCollection<PlayerStatsRow>();
_plPSRList = new ObservableCollection<PlayerStatsRow>();
IEnumerable<KeyValuePair<int, PlayerStats>> players =
_pst.Where(pair => pair.Value.TeamF == _curTeam && !pair.Value.IsHidden);
foreach (var pl in players)
{
_psrList.Add(new PlayerStatsRow(pl.Value, false));
_plPSRList.Add(new PlayerStatsRow(pl.Value, true));
}
_psrList.Sort((row1, row2) => String.CompareOrdinal(row1.LastName, row2.LastName));
_plPSRList.Sort((row1, row2) => String.CompareOrdinal(row1.LastName, row2.LastName));
dgvPlayerStats.ItemsSource = _psrList;
dgvMetricStats.ItemsSource = _psrList;
dgvTeamRoster.ItemsSource = _psrList;
dgvTeamRoster.CanUserAddRows = false;
dgvPlayerPlayoffStats.ItemsSource = _plPSRList;
dgvPlayoffMetricStats.ItemsSource = _plPSRList;
}
示例10: btnEditPlayByPlay_Click
private void btnEditPlayByPlay_Click(object sender, RoutedEventArgs e)
{
tryParseBS(true);
if (!MainWindow.TempBSE_BS.Done)
{
return;
}
var pbpw = new PlayByPlayWindow(
MainWindow.TST,
MainWindow.PST,
new BoxScoreEntry(
MainWindow.TempBSE_BS, MainWindow.TempBSE_PBSLists.SelectMany(list => list).ToList(), MainWindow.TempBSE_PBPEList),
MainWindow.TempBSE_BS.Team1ID,
MainWindow.TempBSE_BS.Team2ID);
if (pbpw.ShowDialog() != true)
{
return;
}
pbpeList = new ObservableCollection<PlayByPlayEntry>(PlayByPlayWindow.SavedPlays);
pbpeList.Sort(new PlayByPlayEntryComparerAsc());
lstPlayByPlay.ItemsSource = pbpeList;
MainWindow.TempBSE_PBPEList = new List<PlayByPlayEntry>(PlayByPlayWindow.SavedPlays);
}
示例11: loadBoxScore
/// <summary>Loads the given box score.</summary>
/// <param name="bse">The BoxScoreEntry to load.</param>
private void loadBoxScore(BoxScoreEntry bse)
{
var bs = bse.BS;
MainWindow.TempBSE_BS = bse.BS;
FillTeamBoxScore(bs);
dtpGameDate.SelectedDate = bs.GameDate;
_curSeason = bs.SeasonNum;
//LinkInternalsToMainWindow();
chkIsPlayoff.IsChecked = bs.IsPlayoff;
calculateScoreAway();
calculateScoreHome();
pbsAwayList = new SortableBindingList<PlayerBoxScore>();
pbsHomeList = new SortableBindingList<PlayerBoxScore>();
pbsAwayList.AllowNew = true;
pbsAwayList.AllowEdit = true;
pbsAwayList.AllowRemove = true;
pbsAwayList.RaiseListChangedEvents = true;
pbsHomeList.AllowNew = true;
pbsHomeList.AllowEdit = true;
pbsHomeList.AllowRemove = true;
pbsHomeList.RaiseListChangedEvents = true;
dgvPlayersAway.ItemsSource = pbsAwayList;
dgvPlayersHome.ItemsSource = pbsHomeList;
_loading = true;
foreach (var pbs in bse.PBSList)
{
if (pbs.TeamID == bs.Team1ID)
{
pbsAwayList.Add(pbs);
}
else
{
pbsHomeList.Add(pbs);
}
}
pbsAwayList.Sort((pbs1, pbs2) => (pbs2.MINS - pbs1.MINS));
pbsHomeList.Sort((pbs1, pbs2) => (pbs2.MINS - pbs1.MINS));
try
{
cmbTeam1.SelectedItem = MainWindow.TST[bs.Team1ID].DisplayName;
cmbTeam2.SelectedItem = MainWindow.TST[bs.Team2ID].DisplayName;
}
catch
{
MessageBox.Show(
"One of the teams requested is disabled for this season. This box score is not available.\n"
+ "To be able to see this box score, enable the teams included in it.");
Close();
}
populateSeasonCombo();
pbpeList = new ObservableCollection<PlayByPlayEntry>(bse.PBPEList);
pbpeList.Sort(new PlayByPlayEntryComparerAsc());
lstPlayByPlay.ItemsSource = pbpeList;
_loading = false;
}
示例12: GetDomainAndPopulateList
private void GetDomainAndPopulateList(IReadOnlyList<Field> fields, string fieldName, ObservableCollection<DomainCodedValuePair> memberCodedValueDomains, bool orderbyName = false)
{
ArcGIS.Core.Data.Field foundField = fields.FirstOrDefault(field => field.Name == fieldName);
//Clear out any old values
memberCodedValueDomains.Clear();
if (foundField != null)
{
Domain domain = foundField.GetDomain();
var codedValueDomain = domain as CodedValueDomain;
SortedList<object, string> codedValuePairs = codedValueDomain.GetCodedValuePairs();
foreach (KeyValuePair<object, string> pair in codedValuePairs)
{
DomainCodedValuePair domainObjectPair = new DomainCodedValuePair(pair.Key, pair.Value);
memberCodedValueDomains.Add(domainObjectPair);
}
if (orderbyName)
{
//Order the collection alphabetically by the names, rather than the default by the code
memberCodedValueDomains.Sort();
}
}
}
示例13: LoadDataGarvis
//.........这里部分代码省略.........
{
string line;
line = reader.ReadLine();
//datetime of data
DataTime = new DateTime(Int64.Parse(line));
Station sta;
string[] sl;
while ((line = reader.ReadLine()) != null)
{
if (line.Length == 0) continue;
try
{
sl = line.Split('|');
sta = new Station();
sta.Id = Int32.Parse(sl[0]);
sta.Code = sl[1];
sta.Name = sl[2];
sta.Classification = GetClassification(sl[3]);
sta.Owner = sl[4];
sta.Position = new MyGeocoordinate(Double.Parse(sl[6], CultureInfo.InvariantCulture), Double.Parse(sl[5], CultureInfo.InvariantCulture));
sta.Quality = Int32.Parse(sl[7]);
if (sl[8] == "") sta.So2.Value = -1; else sta.So2.Value = Double.Parse(sl[8], CultureInfo.InvariantCulture);
sta.So2.State = Int32.Parse(sl[9]);
if (sl[10] == "") sta.No2.Value = -1; else sta.No2.Value = Double.Parse(sl[10], CultureInfo.InvariantCulture);
sta.No2.State = Int32.Parse(sl[11]);
if (sl[12] == "") sta.Co.Value = -1; else sta.Co.Value = Double.Parse(sl[12], CultureInfo.InvariantCulture);
sta.Co.State = Int32.Parse(sl[13]);
if (sl[14] == "") sta.O3.Value = -1; else sta.O3.Value = Double.Parse(sl[14], CultureInfo.InvariantCulture);
sta.O3.State = Int32.Parse(sl[15]);
if (sl[16] == "") sta.Pm10.Value = -1; else sta.Pm10.Value = Double.Parse(sl[16], CultureInfo.InvariantCulture);
sta.Pm10.State = Int32.Parse(sl[17]);
if (sl[18] == "") sta.Pm24.Value = -1; else sta.Pm24.Value = Double.Parse(sl[18], CultureInfo.InvariantCulture);
sta.Pm24.State = Int32.Parse(sl[19]);
//new Time of Last Image
if (sl[20] == "") sta.LastPhoto = null; else sta.LastPhoto = new DateTime(Int64.Parse(sl[20]));
sta.UpdateStatesBasedOnValues();
stations.Add(sta); // Add to list of stations
stationsDict.Add(sta.Code, new object[] {sta.Name, sta.Quality, sta.Position.Longitude, sta.Position.Latitude});
// add count
if (stationCount.ContainsKey(sta.Quality))
{
stationCount[sta.Quality]++;
}
else
{
stationCount.Add(sta.Quality, 1);
}
}
catch (Exception e)
{
throw e;
}
}
}
try
{
//zakomentováno pro účely debuggu
//await SerializationStorage.Save("stations.serial", stationsDict);
}
catch (Exception e)
{
throw e;
}
}
catch(Exception e)
{
throw e;
}
}
//Z nějakého důvodu vyhazuje nullreference exception, z důvodu testování uzavřeno do try
try
{
stations.Sort(i => i.Name);
}
catch (Exception e)
{
throw e;
}
Stations = stations;
IsDataLoaded = true; // Data is loaded
}
示例14: LoadSubtitlesAsync
/// <summary>
/// Get the movie's subtitles according to a language
/// </summary>
/// <param name="movie">The movie of which to retrieve its subtitles</param>
/// <param name="ct">Cancellation token</param>
public async Task LoadSubtitlesAsync(MovieFull movie,
CancellationToken ct)
{
var watch = Stopwatch.StartNew();
var restClient = new RestClient(Constants.YifySubtitlesApi);
var request = new RestRequest("/{segment}", Method.GET);
request.AddUrlSegment("segment", movie.ImdbCode);
try
{
var response = await restClient.ExecuteGetTaskAsync<SubtitlesWrapper>(request, ct);
if (response.ErrorException != null)
throw response.ErrorException;
var wrapper = response.Data;
var subtitles = new ObservableCollection<Subtitle>();
Dictionary<string, List<Subtitle>> movieSubtitles;
if (wrapper.Subtitles == null)
{
await Task.CompletedTask;
return;
}
if (wrapper.Subtitles.TryGetValue(movie.ImdbCode, out movieSubtitles))
{
foreach (var subtitle in movieSubtitles)
{
var sub = subtitle.Value.Aggregate((sub1, sub2) => sub1.Rating > sub2.Rating ? sub1 : sub2);
subtitles.Add(new Subtitle
{
Id = sub.Id,
Language = new CustomLanguage
{
Culture = string.Empty,
EnglishName = subtitle.Key,
LocalizedName = string.Empty
},
Hi = sub.Hi,
Rating = sub.Rating,
Url = sub.Url
});
}
}
subtitles.Sort();
movie.AvailableSubtitles = subtitles;
}
catch (Exception exception) when (exception is TaskCanceledException)
{
Logger.Debug(
"LoadSubtitlesAsync cancelled.");
}
catch (Exception exception)
{
Logger.Error(
$"LoadSubtitlesAsync: {exception.Message}");
throw;
}
finally
{
watch.Stop();
var elapsedMs = watch.ElapsedMilliseconds;
Logger.Debug(
$"LoadSubtitlesAsync ({movie.ImdbCode}) in {elapsedMs} milliseconds.");
}
}