本文整理汇总了C#中System.Collections.ObservableCollection.ElementAt方法的典型用法代码示例。如果您正苦于以下问题:C# ObservableCollection.ElementAt方法的具体用法?C# ObservableCollection.ElementAt怎么用?C# ObservableCollection.ElementAt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.ObservableCollection
的用法示例。
在下文中一共展示了ObservableCollection.ElementAt方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Next
/// <summary>
/// Loads the next track and plays it
/// </summary>
/// <param name="ignoreSingleRepeat">Ignore repeating a single track</param>
/// <param name="startPlayback">Starts the playback</param>
/// <seealso cref="Shuffle"/>
/// <seealso cref="Repeat"/>
/// <seealso cref="HistoryIndex"/>
/// <seealso cref="Queue"/>
public static void Next(bool ignoreSingleRepeat = false, bool startPlayback = false)
{
try
{
// repeat current track?
if (SettingsManager.Repeat == RepeatState.RepeatOne && SettingsManager.CurrentTrack != null && !ignoreSingleRepeat)
{
TrackData t = SettingsManager.CurrentTrack;
Stop();
Load(t);
Play();
return;
}
TrackData nextTrack = null;
List<TrackData> trackCollection = FetchCollectionCallback();
if (trackCollection == null)
{
Stop();
return;
}
if (SettingsManager.CurrentTrack == null)
{
if (trackCollection.Count > 0)
{
nextTrack = (TrackData)trackCollection[0];
SettingsManager.HistoryIndex = SettingsManager.HistoryTracks.Count;
}
else
return;
}
// play track from history?
if (SettingsManager.HistoryIndex < SettingsManager.HistoryTracks.Count - 1)
{
nextTrack = SettingsManager.HistoryTracks.ElementAt<TrackData>(SettingsManager.HistoryIndex + 1);
}
// play track from queue?
else if (SettingsManager.QueueTracks.Count > 0)
nextTrack = SettingsManager.QueueTracks.First<TrackData>();
// play track from track collection
else
{
if (trackCollection.Count < 1) // no track found, nothing more to do here...
{
Stop();
return;
}
// apply search filter
bool ApplySearch = (SearchMatch != null && Filter != null && Filter != "" && Filter != U.T("PlaybackSearch"));
// remove all songs we have already played
ObservableCollection<TrackData> tracksLeft = new ObservableCollection<TrackData>();
foreach (TrackData t in trackCollection)
if (!songsAlreadyPlayed.Contains(t) &&
(!ApplySearch || SearchMatch(t, Filter)))
tracksLeft.Add(t);
if (tracksLeft.Count < 1) // we have played all songs
{
songsAlreadyPlayed.Clear();
if (SettingsManager.Repeat == RepeatState.RepeatAll) // we have repeat on, so we add all track again and start over
{
foreach (TrackData t in trackCollection)
if (!ApplySearch || SearchMatch(t, Filter))
tracksLeft.Add(t);
}
else // repeat is off, so we stop playing
{
Stop();
return;
}
}
if (SettingsManager.Shuffle) // shuffle is on, so we find a random song
{
Random r = new Random();
int x = r.Next(tracksLeft.Count - 1);
nextTrack = tracksLeft.ElementAt<TrackData>(x);
}
else // shuffle is off, so we get the next song in the list
{
if (trackCollection.Count <= 0)
return;
// find CurrentTrack in TrackCollection (Contains() cannot be used since CurrentTrack may be a copy)
//.........这里部分代码省略.........
示例2: CreateCategoryButtons
private ObservableCollection<ScreenCategoryButton> CreateCategoryButtons(ScreenMenu screenMenu)
{
if (screenMenu != null)
{
if (MenuItems != null) MenuItems.Clear();
_currentScreenMenu = screenMenu;
var result = new ObservableCollection<ScreenCategoryButton>();
foreach (var category in screenMenu.Categories.OrderBy(x => x.Order).Where(x => !x.MostUsedItemsCategory))
{
var sButton = new ScreenCategoryButton(category, CategoryCommand);
result.Add(sButton);
}
if (result.Count > 0)
{
var c = result.First();
if (_selectedCategory != null)
c = result.SingleOrDefault(x => x.Category.Name.ToLower() == _selectedCategory.Name.ToLower());
if (c == null && result.Count > 0) c = result.ElementAt(0);
if (c != null) OnCategoryCommandExecute(c.Category);
}
return result;
}
if (MenuItems != null) MenuItems.Clear();
if (Categories != null) Categories.Clear();
_currentScreenMenu = null;
return Categories;
}
示例3: HandleMainWindowLoadedMessage
private void HandleMainWindowLoadedMessage(MainWindowLoadedMessage msg)
{
DispatcherHelper.CheckBeginInvokeOnUI(
async () =>
{
List<string> folders = await _cacheService.GetFoldersAsync();
Folders = new ObservableCollection<string>(folders);
IsShowAllFolders = Properties.Settings.Default.ShowAllFolders;
if (IsShowAllFolders)
{
SelectedFolder = null;
}
else if (!string.IsNullOrWhiteSpace(Properties.Settings.Default.LastFolder))
{
SelectedFolder = Properties.Settings.Default.LastFolder;
}
else if (Folders.Count > 0)
{
SelectedFolder = Folders.ElementAt(0);
}
await LoadDemosHeader();
await RefreshLastRankAccount();
if (!AppSettings.IsInternetConnectionAvailable()) await RefreshBannedPlayerCount();
Messenger.Default.Register<RefreshDemosMessage>(this, HandleRefreshDemosMessage);
Messenger.Default.Register<SelectedAccountChangedMessage>(this, HandleSelectedAccountChangedMessage);
_isMainWindowLoaded = true;
});
}
示例4: HandleMainWindowLoadedMessage
private void HandleMainWindowLoadedMessage(MainWindowLoadedMessage msg)
{
DispatcherHelper.CheckBeginInvokeOnUI(
async () =>
{
List<string> folders = await _cacheService.GetFoldersAsync();
Folders = new ObservableCollection<string>(folders);
IsShowAllFolders = Properties.Settings.Default.ShowAllFolders;
if (IsShowAllFolders)
{
SelectedFolder = null;
}
else if (!string.IsNullOrWhiteSpace(Properties.Settings.Default.LastFolder))
{
SelectedFolder = Properties.Settings.Default.LastFolder;
}
else if (Folders.Count > 0)
{
SelectedFolder = Folders.ElementAt(0);
}
if (!AppSettings.IsInternetConnectionAvailable()) return;
HasNotification = true;
IsBusy = true;
NotificationMessage = "Checking for new banned suspects...";
await RefreshBannedPlayerCount();
HasNotification = false;
IsBusy = false;
});
}
示例5: GetWeatherIcon
/// <summary>
/// Get the link to the weather icon for all the time periods
/// </summary>
/// <param name="xmlWeather"></param>
/// <param name="newForecastList"></param>
private void GetWeatherIcon(XElement xmlWeather, ObservableCollection<ForecastPeriod> newForecastList)
{
XElement xmlCurrent = default(XElement);
int elementIndex = 0;
// get a link to the weather icon for each time period
xmlCurrent = xmlWeather.Descendants("conditions-icon").First();
foreach (XElement curElement in xmlCurrent.Elements("icon-link")) {
try {
newForecastList.ElementAt(elementIndex).ConditionIcon = Convert.ToString(curElement.Value);
} catch (FormatException e1) {
newForecastList.ElementAt(elementIndex).ConditionIcon = "";
}
elementIndex += 1;
}
}
示例6: GetTextForecast
/// <summary>
/// Get the long text forecast for all the time periods
/// </summary>
private void GetTextForecast(XElement xmlWeather, ObservableCollection<ForecastPeriod> newForecastList)
{
XElement xmlCurrent = default(XElement);
int elementIndex = 0;
// get a text forecast for each time period
xmlCurrent = xmlWeather.Descendants("wordedForecast").First();
foreach (XElement curElement in xmlCurrent.Elements("text")) {
try {
newForecastList.ElementAt(elementIndex).TextForecast = Convert.ToString(curElement.Value);
} catch (FormatException e1) {
newForecastList.ElementAt(elementIndex).TextForecast = "";
}
elementIndex += 1;
}
}
示例7: GetMinMaxTemperatures
/// <summary>
/// Get the minimum and maximum temperatures for all the time periods
/// </summary>
private void GetMinMaxTemperatures(XElement xmlWeather, ObservableCollection<ForecastPeriod> newForecastList)
{
XElement xmlCurrent = default(XElement);
// Find the temperature parameters. if first time period is "Tonight",
// then the Daily Minimum Temperatures are listed first.
// Otherwise the Daily Maximum Temperatures are listed first
xmlCurrent = xmlWeather.Descendants("parameters").First();
int minTemperatureIndex = 1;
int maxTemperatureIndex = 0;
// If "Tonight" is the first time period, then store Daily Minimum
// Temperatures first, then Daily Maximum Temperatuers next
if (newForecastList.ElementAt(0).TimeName == "Tonight") {
minTemperatureIndex = 0;
maxTemperatureIndex = 1;
// get the Daily Minimum Temperatures
foreach (XElement curElement in xmlCurrent.Elements("temperature").ElementAt(0).Elements("value")) {
newForecastList.ElementAt(minTemperatureIndex).Temperature = int.Parse(curElement.Value);
minTemperatureIndex += 2;
}
// then get the Daily Maximum Temperatures
foreach (XElement curElement in xmlCurrent.Elements("temperature").ElementAt(1).Elements("value")) {
newForecastList.ElementAt(maxTemperatureIndex).Temperature = int.Parse(curElement.Value);
maxTemperatureIndex += 2;
}
// otherwise we have a daytime time period first
} else {
// get the Daily Maximum Temperatures
foreach (XElement curElement in xmlCurrent.Elements("temperature").ElementAt(0).Elements("value")) {
newForecastList.ElementAt(maxTemperatureIndex).Temperature = int.Parse(curElement.Value);
maxTemperatureIndex += 2;
}
// then get the Daily Minimum Temperatures
foreach (XElement curElement in xmlCurrent.Elements("temperature").ElementAt(1).Elements("value")) {
newForecastList.ElementAt(minTemperatureIndex).Temperature = int.Parse(curElement.Value);
minTemperatureIndex += 2;
}
}
}
示例8: GetCurrentConditions
/// <summary>
/// Get the current conditions for all the time periods
/// </summary>
private void GetCurrentConditions(XElement xmlWeather, ObservableCollection<ForecastPeriod> newForecastList)
{
XElement xmlCurrent = default(XElement);
int elementIndex = 0;
// now get the current weather conditions for each time period
xmlCurrent = xmlWeather.Descendants("weather").First();
foreach (XElement curElement in xmlCurrent.Elements("weather-conditions")) {
try {
newForecastList.ElementAt(elementIndex).WeatherType = Convert.ToString(curElement.Attribute("weather-summary").Value);
} catch (FormatException e1) {
newForecastList.ElementAt(elementIndex).WeatherType = "";
}
elementIndex += 1;
}
}
示例9: GetChancePrecipitation
/// <summary>
/// Get the chance of precipitation for all the time periods
/// </summary>
private void GetChancePrecipitation(XElement xmlWeather, ObservableCollection<ForecastPeriod> newForecastList)
{
XElement xmlCurrent = default(XElement);
// now find the probablity of precipitation for each time period
xmlCurrent = xmlWeather.Descendants("probability-of-precipitation").First();
int elementIndex = 0;
foreach (XElement curElement in xmlCurrent.Elements("value")) {
try {
newForecastList.ElementAt(elementIndex).ChancePrecipitation = int.Parse(curElement.Value);
// some values are nil
} catch (FormatException e1) {
newForecastList.ElementAt(elementIndex).ChancePrecipitation = 0;
}
elementIndex += 1;
}
}