本文整理汇总了C#中ObservableCollection.Contains方法的典型用法代码示例。如果您正苦于以下问题:C# ObservableCollection.Contains方法的具体用法?C# ObservableCollection.Contains怎么用?C# ObservableCollection.Contains使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ObservableCollection
的用法示例。
在下文中一共展示了ObservableCollection.Contains方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Init
private void Init()
{
DateTimeClocks = new ObservableCollection<ClockRecord>(Respostory.GetAllClockRecord());
TestBeer = new RelayCommand(() => BeepVulous.Beep(1000, 1000));
TestEmail = new RelayCommand(() =>
{
if (null != CurrentDateTimeClock)
EmailSend.Send(CurrentDateTimeClock.EmailAdress, "测试邮件");
});
AddRecord = new RelayCommand(() =>
{
if (!DateTimeClocks.Contains(CurrentDateTimeClock))
{
DateTimeClocks.Insert(0, CurrentDateTimeClock);
Respostory.InsertRecore(CurrentDateTimeClock);
}
}
);
DeleteRecord = new RelayCommand(() =>
{
if (DateTimeClocks.Contains(CurrentDateTimeClock))
{
DateTimeClocks.Remove(CurrentDateTimeClock);
Respostory.DeleteRecore(CurrentDateTimeClock);
}
}
);
}
示例2: HidManager
public HidManager()
{
HidDeviceLoader = new HidDeviceLoader();
FoundDevices = new ObservableCollection<HidDeviceRepresentation>();
_hidScanThread = new Thread(() =>
{
while (true)
{
var currentDevices = HidDeviceLoader.GetDevices().Select(hidDevice => new HidDeviceRepresentation(hidDevice)).ToList();
if (!Thread.CurrentThread.IsAlive) { break; }
Application.Current.Dispatcher.Invoke(() =>
{
foreach (var newDevice in currentDevices.Where(device => !FoundDevices.Contains(device)))
{
FoundDevices.Add(newDevice);
}
});
Thread.Sleep(TimeSpan.FromSeconds(10));
}
// ReSharper disable once FunctionNeverReturns
});
_hidScanThread.Start();
}
示例3: DeviceGuardZoneViewModel
public DeviceGuardZoneViewModel(GKDeviceGuardZone deviceGuardZone, GKDevice device)
{
DeviceGuardZone = deviceGuardZone;
if (device != null)
IsCodeReader = device.Driver.IsCardReaderOrCodeReader;
No = deviceGuardZone.GuardZone.No;
Name = deviceGuardZone.GuardZone.Name;
Description = deviceGuardZone.GuardZone.Description;
ActionTypes = new ObservableCollection<GKGuardZoneDeviceActionType>();
if (device != null)
switch (device.DriverType)
{
case GKDriverType.RSR2_GuardDetector:
case GKDriverType.RSR2_GuardDetectorSound:
case GKDriverType.RSR2_HandGuardDetector:
ActionTypes.Add(GKGuardZoneDeviceActionType.SetAlarm);
break;
case GKDriverType.RSR2_AM_1:
case GKDriverType.RSR2_MAP4:
ActionTypes.Add(GKGuardZoneDeviceActionType.SetGuard);
ActionTypes.Add(GKGuardZoneDeviceActionType.ResetGuard);
ActionTypes.Add(GKGuardZoneDeviceActionType.ChangeGuard);
ActionTypes.Add(GKGuardZoneDeviceActionType.SetAlarm);
break;
}
if (deviceGuardZone.ActionType == null || !ActionTypes.Contains(deviceGuardZone.ActionType.Value))
SelectedActionType = ActionTypes.FirstOrDefault();
ShowPropertiesCommand = new RelayCommand(OnShowProperties);
}
示例4: GroupHistoryViewModel
public GroupHistoryViewModel(IStockProvider dataService)
{
_dataService = dataService;
StockGroups = new ObservableCollection<StockQuoteGroup>();
var groupingsStream = from quote in _dataService.StockQuoteStream.ObserveOnDispatcher()
group quote by quote.Symbol into company
let grp = new StockQuoteGroup(company.Key)
from quote in company
select new
{
Group = grp,
Quote = quote
};
var res = groupingsStream.Select(item =>
{
//Add it to the list of all groups if it doesn't exist
if (!StockGroups.Contains(item.Group))
{
StockGroups.Insert(0, item.Group);
}
item.Group.Quotes.Insert(0, item.Quote);
item.Group.Latest = item.Quote;
return item;
});
res.Subscribe();
}
示例5: Init
private void Init()
{
Musicses = new ObservableCollection<Musics>(Respostory.GetAllMusic());
InsertMusic = new RelayCommand(() =>
{
if (!Musicses.Contains(SelectMusic))
{
Musicses.Insert(0, SelectMusic);
Respostory.InsertMusic(SelectMusic);
}
});
LastMusic=new RelayCommand(() =>
{
_incuten = Musicses.IndexOf(SelectMusic);
if (-1 != _incuten)
{
SelectMusic = Musicses[_incuten - 1 >= 0 ? _incuten - 1 : 0];
}
});
NextMusic = new RelayCommand(() =>
{
_incuten = Musicses.IndexOf(SelectMusic);
if (-1 != _incuten)
{
SelectMusic = Musicses[_incuten + 1 < Musicses.Count ? _incuten + 1 : Musicses.Count-1];
}
});
}
示例6: UpdateIcons
private void UpdateIcons() {
Icons = new ObservableCollection<FilesStorage.ContentEntry>(FilesStorage.Instance.GetContentDirectory(ContentCategory.UpgradeIcons));
if (Icons.Contains(Selected)) return;
var previous = ValuesStorage.GetString(_key);
Selected = (previous != null ? Icons.FirstOrDefault(x => x.Name == previous) : null) ?? (Icons.Count > 0 ? Icons[0] : null);
}
示例7: AppGrabberUI
public AppGrabberUI(AppGrabber appGrabber)
{
this.appGrabber = appGrabber;
InitializeComponent();
// Grab the Programs
List<ApplicationInfo> apps = appGrabber.ProgramList;
// Now to add them to the list on the AppGrabber
// Create ObservableCollections to bind to the ListViews
ObservableCollection<ApplicationInfo> installedAppsCollection = new ObservableCollection<ApplicationInfo>();
programsMenuAppsCollection = new ObservableCollection<ApplicationInfo>(appGrabber.CategoryList.FlatList.ToList());
InstalledAppsView.ItemsSource = installedAppsCollection;
ProgramsMenuAppsView.ItemsSource = programsMenuAppsCollection;
// Need to use an event handler to remove Apps from categories when moved to the "Installed Applications" listing
programsMenuAppsCollection.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(programsMenuAppsCollection_CollectionChanged);
// Iterate thru the apps, creating ApplicationInfoPanels and
// add them to the installedAppsCollection
foreach (ApplicationInfo app in apps)
{
if (!programsMenuAppsCollection.Contains(app)) {
installedAppsCollection.Add(app);
}
}
AppViewSorter.Sort(installedAppsCollection, "Name");
AppViewSorter.Sort (programsMenuAppsCollection, "Name");
GC.Collect ();
}
示例8: PopupViewModel
public PopupViewModel()
{
Locations = new ObservableCollection<PopupLocationItem>();
LocationSelectedCommand = new Command<PopupLocationItem>((item) =>
{
if (!Locations.Contains(item)) return;
foreach (PopupLocationItem items in Locations)
{
items.IsSelected = false;
}
item.IsSelected = true;
if (LocationSelected != null)
{
LocationSelected(this, item);
}
});
LocationRemovedCommand = new Command<PopupLocationItem>((item) =>
{
Locations.Remove(item);
if (LocationRemoved != null)
{
LocationRemoved(this, item);
}
});
}
示例9: CollectionContainsItem
public static bool CollectionContainsItem(ObservableCollection<string> collection,
string item)
{
bool contains = false;
if (collection != null)
GUIDispatcher.Invoke((Action)(() => { contains = collection.Contains(item); }));
else
throw new ArgumentNullException("Collection can not be null");
return contains;
}
示例10: WhenGridViewSelectedItemsChange_SelectedItemsCollectionIsUpdated
public void WhenGridViewSelectedItemsChange_SelectedItemsCollectionIsUpdated()
{
// Arrange.
var item1 = new object();
var item2 = new object();
var grid = new RadGridView { SelectionMode = SelectionMode.Multiple, ItemsSource = new[] { item1, item2 } };
var behavior = new GridViewMultiSelectBehavior();
var selectedItems = new ObservableCollection<object>();
behavior.Attach(grid);
behavior.SelectedItems = selectedItems;
// Act.
grid.SelectedItems.Add(item1);
// Assert
Assert.AreEqual(1, selectedItems.Count);
Assert.IsTrue(selectedItems.Contains(item1));
// Act.
grid.SelectedItems.Add(item2);
// Assert.
Assert.AreEqual(2, selectedItems.Count);
Assert.IsTrue(selectedItems.Contains(item1));
Assert.IsTrue(selectedItems.Contains(item2));
// Act.
grid.SelectedItems.Remove(item1);
// Assert.
Assert.AreEqual(1, selectedItems.Count);
Assert.IsTrue(selectedItems.Contains(item2));
// Act.
grid.SelectedItems.Clear();
// Assert.
Assert.AreEqual(0, selectedItems.Count);
}
示例11: SearchAlbums
public static void SearchAlbums(string tag, ObservableCollection<AlbumItem> results)
{
var albums = SearchAlbumItems(tag);
foreach (var album in albums)
{
if (!results.Contains(album))
results.Add(album);
}
foreach (var result in results.ToList())
{
if (!albums.Contains(result))
results.Remove(result);
}
}
示例12: SetBooking
public void SetBooking(Booking booking, SubmitBookingResponse submitBookingResponse)
{
if (booking == null)
return;
_booking = booking;
Email3 = Email4 = null;
CreatorEmails = new ObservableCollection<string>(submitBookingResponse.CreatorEmails);
if (!string.IsNullOrWhiteSpace(_booking.Creator.Email) && !CreatorEmails.Contains(_booking.Creator.Email))
CreatorEmails.Insert(0, _booking.Creator.Email);
OnPropertyChanged(() => CreatorEmails);
}
示例13: AllAvoidAttackMoves
public static ObservableCollection<Move> AllAvoidAttackMoves()
{
ObservableCollection<Piece> attackablePieces = new ObservableCollection<Piece>();
foreach (Move move in This.Game.OppositePlayer.AllMoves())
{
if (move.EndPosition.Piece != null && !attackablePieces.Contains(move.EndPosition.Piece))
attackablePieces.Add(move.EndPosition.Piece);
}
ObservableCollection<Move> possible = new ObservableCollection<Move>();
foreach (Piece piece in attackablePieces)
{
possible.AddRange<Move>(piece.LegalMoves);
}
return possible;
}
示例14: parseTermIntoKGrams
public ObservableCollection<String> parseTermIntoKGrams(String term)
{
var kGrams = new ObservableCollection<String>();
var kGram = "";
kGrams.Add(" " + term[0]);
for (int i = 0; i < term.Length - 1; i++)
{
kGram = term.Substring(i, 2);
if (!kGrams.Contains(kGram))
{
kGrams.Add(kGram);
}
}
return kGrams;
}
示例15: DefaultTaskViewModel
/// <summary>
/// Constructor of the class
/// </summary>
/// <param name="taskModel"></param>
/// <param name="targetList"></param>
/// <param name="dataConnector"></param>
/// <param name="mainPage"></param>
/// <param name="state"></param>
public DefaultTaskViewModel(ITaskModel taskModel, ObservableCollection<ITaskViewModel> targetList, IDataConnector dataConnector, MainPage mainPage, TaskState state)
{
TaskModel = taskModel;
_targetList = targetList;
_dataConnector = dataConnector;
ItemVisualWidth = mainPage.ActualWidth;
// Commands
Break = new ViewModelCommand()
{
Command = new RelayCommand(r => BreakTask()),
Text = "Break"
};
PunchOut = new ViewModelCommand
{
Command = new RelayCommand(r => FinishTask()),
Text = "Finished",
ImagePath = @"Images/finish.png"
};
DeleteFromList = new ViewModelCommand
{
Command = new RelayCommand(
r =>
{
if (targetList != null && targetList.Contains(this))
{
targetList.Remove(this);
_dataConnector.DeleteTask(taskModel.Id);
}
}),
Text = "Delete",
ImagePath = "Images/delete.png"
};
// Timer Init
_timer = new DispatcherTimer();
_timer.Tick += timer_Tick;
_timer.Interval = TimeSpan.FromSeconds(1);
_timer.Start();
// Setstate
State = state;
_initLoad = false;
}