本文整理汇总了C#中System.Collections.ObservableCollection.Contains方法的典型用法代码示例。如果您正苦于以下问题:C# ObservableCollection.Contains方法的具体用法?C# ObservableCollection.Contains怎么用?C# ObservableCollection.Contains使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.ObservableCollection
的用法示例。
在下文中一共展示了ObservableCollection.Contains方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InitValues
private void InitValues()
{
Values = new ObservableCollection<IOrderable>(_values);
foreach (var item in SelectedValues)
{
if (Values.Contains(item))
Values.Remove(item);
}
}
示例2: removeWizardPages
// Removes the wizard pages of the passed-in search providers from the search tool's configuration wizard
private void removeWizardPages(IEnumerable providers, ObservableCollection<WizardPage> pages)
{
foreach (ISearchProvider provider in providers)
{
ISupportsWizardConfiguration wizardInfo = provider as ISupportsWizardConfiguration;
if (wizardInfo != null)
{
foreach (WizardPage page in wizardInfo.Pages)
{
if (pages.Contains(page))
pages.Remove(page);
}
}
}
}
示例3: ParsePLS
/// <summary>
/// Parses a PLS playlist and returns the tracks of it.
/// </summary>
/// <param name="reader">The data stream of the playlist</param>
/// <param name="path">The relative path of the tracks in the playlist</param>
/// <returns>A collection of tracks represented by the playlist</returns>
private static ObservableCollection<TrackData> ParsePLS(StreamReader reader, string path = "")
{
ObservableCollection<TrackData> ret = new ObservableCollection<TrackData>();
bool hdr = false;
string version = "";
int noe = 0;
int nr = 0;
string line;
List<string> lines = new List<string>();
while ((line = reader.ReadLine()) != null)
{
lines.Add(line);
nr++;
if (line == "[playlist]")
hdr = true;
else if (!hdr)
U.L(LogLevel.Warning, "PLAYLIST", "Bad format on line "
+ nr + ": expecting '[playlist]'");
else if (line.StartsWith("NumberOfEntries="))
noe = Convert.ToInt32(line.Split('=')[1]);
else if (line.StartsWith("Version="))
version = line.Split('=')[1];
}
if (!hdr)
U.L(LogLevel.Warning, "PLAYLIST", "No header found");
// It seems there's many Internet radios that doesn't specify a version,
// so we can't be too picky about this one.
//else if (version != "2")
// U.L(LogLevel.Warning, "PLAYLIST", "Unsupported version '" +
// version + "'");
else
{
string[,] tracks = new string[noe, 3];
nr = 0;
foreach (string l in lines)
{
if (l.StartsWith("File") || l.StartsWith("Title") || l.StartsWith("Length"))
{
int tmp = 4;
int index = 0;
if (l.StartsWith("Title")) { tmp = 5; index = 1; }
else if (l.StartsWith("Length")) { tmp = 6; index = 2; }
string[] split = l.Split('=');
int number = Convert.ToInt32(split[0].Substring(tmp));
if (number > noe)
U.L(LogLevel.Warning, "PLAYLIST", "Bad format on line "
+ nr + ": entry number is '" + number + "' but NumberOfEntries is '" + noe + "'");
else
tracks[number - 1, index] = split[1];
}
else if (!l.StartsWith("NumberOfEntries") && l != "[playlist]" && !l.StartsWith("Version="))
{
U.L(LogLevel.Warning, "PLAYLIST", "Bad format on line "
+ nr + ": unexpected '" + l + "'");
}
}
for (int i = 0; i < noe; i++)
{
string p = tracks[i, 0];
TrackType type = MediaManager.GetType(p);
TrackData track;
switch (type)
{
case TrackType.File:
if (!File.Exists(p) && File.Exists(Path.Combine(path, p)))
p = Path.Combine(path, p);
if (File.Exists(p))
{
if (!FilesystemManager.PathIsAdded(p))
FilesystemManager.AddSource(p);
foreach (TrackData t in SettingsManager.FileTracks)
if (t.Path == p)
{
if (!ret.Contains(t))
ret.Add(t);
break;
}
}
break;
case TrackType.WebRadio:
track = MediaManager.ParseURL(p);
if (track != null && !ret.Contains(track))
{
//.........这里部分代码省略.........
示例4: ParseM3U
/// <summary>
/// Parses an M3U playlist and returns the tracks of it.
/// </summary>
/// <param name="reader">The data stream of the playlist</param>
/// <param name="path">The relative path of the tracks in the playlist</param>
/// <returns>A collection of tracks represented by the playlist</returns>
private static ObservableCollection<TrackData> ParseM3U(StreamReader reader, string path = "")
{
ObservableCollection<TrackData> ret = new ObservableCollection<TrackData>();
string line;
bool ext = false;
string inf = "";
int nr = 0;
while ((line = reader.ReadLine()) != null)
{
nr++;
if (line == "#EXTM3U")
ext = true;
else if (ext && line.StartsWith("#EXTINF:"))
inf = line.Substring(8);
else if (line.StartsWith("#") || line == "")
continue;
else
{
string p = line;
TrackType type = MediaManager.GetType(p);
TrackData track;
switch (type)
{
case TrackType.File:
if (!File.Exists(p) && File.Exists(Path.Combine(path, p)))
p = Path.Combine(path, p);
if (File.Exists(path))
{
string length = "";
string artist = "";
string title = "";
if (inf != "")
{
if (!inf.Contains(','))
{
U.L(LogLevel.Warning, "PLAYLIST", "Bad format on line "
+ nr + ": expecting ','");
continue;
}
string[] split = inf.Split(',');
length = split[0];
if (split[1].Contains('-'))
{
artist = split[1].Split('-')[0];
title = split[1].Split('-')[1];
}
else
title = split[1];
}
if (!FilesystemManager.PathIsAdded(path))
FilesystemManager.AddSource(p);
foreach (TrackData t in SettingsManager.FileTracks)
if (t.Path == path)
{
if (!ret.Contains(t))
ret.Add(t);
break;
}
inf = "";
}
break;
case TrackType.WebRadio:
track = MediaManager.ParseURL(p);
if (track != null && !ret.Contains(track))
ret.Add(track);
break;
case TrackType.YouTube:
track = YouTubeManager.CreateTrack(p);
if (track != null && !ret.Contains(track))
ret.Add(track);
break;
case TrackType.SoundCloud:
track = SoundCloudManager.CreateTrack(p);
if (track != null && !ret.Contains(track))
ret.Add(track);
break;
}
}
}
return ret;
}
示例5: ContainsTest
public static void ContainsTest()
{
string[] anArray = new string[] { "one", "two", "three", "four" };
ObservableCollection<string> collection = new ObservableCollection<string>((IEnumerable<string>)anArray);
string collectionString = "";
foreach (var item in collection)
collectionString += item + ", ";
for (int i = 0; i < collection.Count; ++i)
Assert.True(collection.Contains(anArray[i]), "ObservableCollection did not contain the item: " + anArray[i] + " Collection: " + collectionString);
string g = "six";
Assert.False(collection.Contains(g), "Collection contained an item that should not have been there. guid: " + g + " Collection: " + collectionString);
Assert.False(collection.Contains(null), "Collection should not have contained null. Collection: " + collectionString);
}
示例6: RemoveAtTest
public static void RemoveAtTest()
{
Guid[] anArray = { Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid() };
ObservableCollection<Guid> col0 = new ObservableCollection<Guid>((IEnumerable<Guid>)anArray);
ObservableCollection<Guid> col1 = new ObservableCollection<Guid>((IEnumerable<Guid>)anArray);
ObservableCollection<Guid> col2 = new ObservableCollection<Guid>((IEnumerable<Guid>)anArray);
col0.RemoveAt(0);
string collectionString = "";
foreach (var item in col1)
collectionString += item + ", ";
Assert.False(col0.Contains(anArray[0]), "Collection0 should no longer contain the item: " + anArray[0] + " Collection: " + collectionString);
col1.RemoveAt(1);
collectionString = "";
foreach (var item in col1)
collectionString += item + ", ";
Assert.False(col1.Contains(anArray[1]), "Collection1 should no longer contain the item: " + anArray[1] + " Collection: " + collectionString);
col2.RemoveAt(2);
collectionString = "";
foreach (var item in col2)
collectionString += item + ", ";
Assert.False(col2.Contains(anArray[2]), "Collection2 should no longer contain the item: " + anArray[2] + " Collection: " + collectionString);
string[] anArrayString = { "one", "two", "three", "four" };
ObservableCollection<string> col = new ObservableCollection<string>(anArrayString);
CollectionAndPropertyChangedTester helper = new CollectionAndPropertyChangedTester();
helper.RemoveItemAtTest(col, 1);
}
示例7: ListViewMouseLeftButtonDown
/// <summary>
/// Starts the Drag if the Item under the curser is a valid Drag Item
/// </summary>
/// <param name="sender">not used</param>
/// <param name="e">MousePos</param>
void ListViewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
int index = GetCurrentIndex(e.GetPosition);
// check to see if drag can be done
FrameworkElement ele = e.OriginalSource as FrameworkElement;
if (ele != null && ele.DataContext != null)
{
if (ele.DataContext.GetType() != typeof(Mp3Song) && ele.DataContext.GetType() != typeof(Song))
return;
}
const DragDropEffects allowedEffects = DragDropEffects.Move;
if (e.LeftButton != MouseButtonState.Pressed || e.ClickCount != 1)
return;
var draggSongs = new ObservableCollection<ISong>();
foreach (ISong song in listView.SelectedItems)
draggSongs.Add(song);
ISong actDragSong = listView.Items[index] as ISong;
if (listView.SelectedItems.Count < 2)
{
if (!draggSongs.Contains(actDragSong))
draggSongs.Clear();
draggSongs.Add(actDragSong);
}
else
{
if (!draggSongs.Contains(actDragSong))
return;
}
try
{
DragDrop.DoDragDrop(listView, draggSongs, allowedEffects);
}
catch (ArgumentNullException)
{}
catch (NullReferenceException)
{}
ColorCurrentPlayedSong();
}
示例8: CheckObjectValidationForFields
/// <summary>
/// Checks the object validation for fields warnings or errors.
/// </summary>
/// <param name="value">The value.</param>
/// <param name="propertyChanged">The property changed.</param>
/// <param name="infoList">The info list containing the warning or error info.</param>
/// <param name="validationType">Type of the validation.</param>
private static void CheckObjectValidationForFields(object value, string propertyChanged, ObservableCollection<FieldWarningOrErrorInfo> infoList,
ValidationType validationType)
{
if (string.IsNullOrEmpty(propertyChanged))
{
infoList.Clear();
}
else
{
for (int i = 0; i < infoList.Count; i++)
{
if (string.Compare(infoList[i].Field, propertyChanged) == 0)
{
infoList.RemoveAt(i);
}
}
}
Dictionary<string, string> fieldWarningsOrErrors = CheckFieldWarningsOrErrors(value, propertyChanged, validationType);
foreach (var fieldWarningOrError in fieldWarningsOrErrors)
{
var fieldWarningOrErrorInfo = new FieldWarningOrErrorInfo(fieldWarningOrError.Key, fieldWarningOrError.Value);
if (!infoList.Contains(fieldWarningOrErrorInfo))
{
infoList.Add(new FieldWarningOrErrorInfo(fieldWarningOrError.Key, fieldWarningOrError.Value));
}
}
}
示例9: RestoreList
public void RestoreList(string filepath)
{
using (FileStream fs = File.Open(filepath, FileMode.Open, FileAccess.Read))
{
AccessList = new ObservableCollection<AccessListEntry>();
StreamReader sr = new StreamReader(fs);
string line;
while((line = sr.ReadLine()) != null)
{
AccessListEntry e;
if (GenerateEntryFromString(line, out e))
if (!AccessList.Contains(e))
AccessList.Add(e);
}
//sr.Close();
}
}
示例10: UpdatePlayers
/// <summary>
/// Updates the current players
/// </summary>
/// <returns></returns>
public void UpdatePlayers()
{
IPGlobalProperties ipGlobalProperties = IPGlobalProperties.GetIPGlobalProperties();
TcpConnectionInformation[] connectionInformation = ipGlobalProperties.GetActiveTcpConnections();
IEnumerator enumerator = connectionInformation.GetEnumerator();
int count = 0;
ObservableCollection<IPAddress> current = new ObservableCollection<IPAddress>();
ObservableCollection<IPAddress> all = new ObservableCollection<IPAddress>(Players);
while (enumerator.MoveNext())
{
TcpConnectionInformation info = (TcpConnectionInformation)enumerator.Current;
if (info.LocalEndPoint.Port == 12345 && info.State == TcpState.Established)
{
count++;
if (!all.Contains(info.RemoteEndPoint.Address))
all.Add(info.RemoteEndPoint.Address);
current.Add(info.RemoteEndPoint.Address);
}
}
#if DEBUG
//Time for some debug data
Random rnd = new Random();
int playersToGenerate = rnd.Next(1, 10);
for (int i = 0; i < playersToGenerate; i++)
{
int a = rnd.Next(0, 255);
IPAddress tmp;
string ip = "127.0.0." + a.ToString();
if (IPAddress.TryParse(ip, out tmp))
{
if (!current.Contains(tmp))
current.Add(tmp);
if (!all.Contains(tmp))
all.Add(tmp);
}
}
#endif
ConnectedPlayers = current;
Players = all;
}
示例11: RefreshConsumedProperties
private void RefreshConsumedProperties(ObservableCollection<PropertyEntry> unconsumedProperties, ObservableCollection<PropertyEntry> allProperties, ObservableCollection<CategoryEditor> categoryEditors)
{
if (allProperties == null || unconsumedProperties == null || unconsumedProperties.Count == allProperties.Count)
{
return;
}
foreach (PropertyEntry property in allProperties)
{
if (!unconsumedProperties.Contains(property))
{
// The following method will only add the specified property to the unconsumed
// list if it isn't already consumed by some existing category editor.
AddProperty(property, unconsumedProperties, allProperties, categoryEditors);
}
}
}
示例12: AddProperty
// ###################################################
// CIDER-SPECIFIC CHANGE IN NEED OF PORTING - BEGIN
// ###################################################
// This method used to be non-virtual, private
protected virtual void AddProperty(PropertyEntry property, ObservableCollection<PropertyEntry> unconsumedProperties, ObservableCollection<PropertyEntry> referenceOrder, ObservableCollection<CategoryEditor> categoryEditors)
{
// ###################################################
// CIDER-SPECIFIC CHANGE IN NEED OF PORTING - END
// ###################################################
bool consumed = false;
foreach (CategoryEditor categoryEditor in categoryEditors)
{
if (categoryEditor.ConsumesProperty(property))
{
consumed = true;
}
}
if (!consumed)
{
// We need to insert this property in the correct location. Reference order is sorted and contains all properties in the unconsumed properties collection.
Fx.Assert(referenceOrder.Contains(property), "Reference order should contain the property to be added.");
#if DEBUG
foreach (PropertyEntry unconsumedProperty in unconsumedProperties)
{
Fx.Assert(referenceOrder.Contains(unconsumedProperty), "Reference order should contain all unconsumed properties.");
}
#endif
// We'll walk both collections, and advance the insertion index whenever we see an unconsumed property come ahead of the target in the reference order.
int referenceIndex = 0;
int insertionIndex = 0;
while (referenceOrder[referenceIndex] != property && insertionIndex < unconsumedProperties.Count)
{
if (unconsumedProperties[insertionIndex] == referenceOrder[referenceIndex])
{
insertionIndex++;
}
referenceIndex++;
}
unconsumedProperties.Insert(insertionIndex, property);
}
}
示例13: Test_ObservableCollection_Contains
public void Test_ObservableCollection_Contains()
{
var list = new ObservableCollection<int>() { 6, 5, 8 };
Assert.Equal(3, list.Count);
Assert.True(list.Contains(6));
Assert.True(list.Contains(5));
Assert.True(list.Contains(8));
Assert.False(list.Contains(9));
}
示例14: RefreshJobOrders
private void RefreshJobOrders()
{
if (this.Order == null || this.SelectedSupplier == null)
return;
//Select the Job Orders
var activeJobOrders = new ObservableCollection<JobOrder>();
foreach (var dyeingJo in Order.DyeingJOes)
{
if (dyeingJo.Supplier == this.SelectedSupplier && dyeingJo.JobOrder != null && !activeJobOrders.Contains(dyeingJo.JobOrder)
&& dyeingJo.JobOrder.IsIssued == false)
{
activeJobOrders.Add(dyeingJo.JobOrder);
}
}
foreach (var knittingJo in Order.KnittingJOes)
{
if (knittingJo.Supplier == this.SelectedSupplier && knittingJo.JobOrder != null && !activeJobOrders.Contains(knittingJo.JobOrder)
&& knittingJo.JobOrder.IsIssued == false)
{
activeJobOrders.Add(knittingJo.JobOrder);
}
}
foreach (var compactingJo in Order.CompactingJoes)
{
if (compactingJo.Supplier == this.SelectedSupplier && compactingJo.JobOrder != null && !activeJobOrders.Contains(compactingJo.JobOrder)
&& compactingJo.JobOrder.IsIssued == false)
{
activeJobOrders.Add(compactingJo.JobOrder);
}
}
foreach (var jo in this.SelectedSupplier.JobOrders)
{
if (jo.GRNReciept != null && jo.GRNReciept.OrderedItem.PurchaseOrder.Order == this.Order && !activeJobOrders.Contains(jo) && jo.IsIssued == false)
{
activeJobOrders.Add(jo);
}
}
JobOrders = activeJobOrders;
}
示例15: Search
private void Search()
{
if (Database == null) return;
// Make full-text search in DB limited to 1000 items and 2 seconds
// without results sorting
var prefixes = Database.SearchPrefix(tbSearch.Text, 1000, 2000, false);
var contacts = new ObservableCollection<Contact>();
var leads = new ObservableCollection<Lead>();
var activities = new ObservableCollection<Activity>();
var arrayRes = new List<FullTextSearchHit>();
if (prefixes != null) arrayRes.AddRange(prefixes.Hits);
foreach (var hit in arrayRes)
{
if (hit.Document is Contact)
{
if (!contacts.Contains((Contact)hit.Document))
contacts.Add((Contact)hit.Document);
}
else if (hit.Document is Lead)
{
if (!leads.Contains((Lead)hit.Document))
leads.Add((Lead)hit.Document);
}
else if (hit.Document is Activity)
{
if (!activities.Contains((Activity)hit.Document))
activities.Add((Activity)hit.Document);
}
}
gridContact.ItemsSource = contacts;
gridLead.ItemsSource = leads;
gridActivity.ItemsSource = activities;
}