本文整理汇总了C#中System.Collections.ObservableCollection.AddRange方法的典型用法代码示例。如果您正苦于以下问题:C# ObservableCollection.AddRange方法的具体用法?C# ObservableCollection.AddRange怎么用?C# ObservableCollection.AddRange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.ObservableCollection
的用法示例。
在下文中一共展示了ObservableCollection.AddRange方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SelectMetaDataWindowVM
public SelectMetaDataWindowVM(BookRelationType bookRelationType, string metaDataId)
{
this.bookRelationType = bookRelationType;
bookRelationItems = new ObservableCollection<BookRelationItem>();
bookRelationItems.AddRange(BookRelationItem.All);
this.allObjects = new ObservableCollection<ITitleProvider>();
this.objects = new ObservableCollection<ITitleProvider>();
this.metaDataId = metaDataId;
}
示例2: PerformSearch
public void PerformSearch()
{
try
{
logger.Debug("Searching for projects with Name=\"{0}\" Left=\"{1}\" Right=\"{2}\"", SearchName, SearchLeftDate, SearchRightDate);
SearchHeader = "Search Settings - Searching";
logger.Info("Starting the search!");
databaseService.SearchProjects(SearchName, SearchNumber, SearchLeftDate, SearchRightDate).ContinueWith((Task<IList<Project>> task) =>
{
logger.Info("Search finished!");
var results = task.Result;
DispatcherHelper.CheckBeginInvokeOnUI(() =>
{
try
{
_searchResults = new ObservableCollection<HistorySearchResult>();
_searchResults.AddRange(results.OrderBy(x => x.Created).Select(x => new HistorySearchResult(x)));
OnPropertyChanged(nameof(SearchResults));
IsSearching = false;
SearchHeader = string.Format("Search Settings - {0} results", SearchResults.Count);
logger.Debug("Finisehd search with {0} results.", SearchResults.Count);
}
catch (Exception exp)
{
logger.Error(exp, "Search failed.");
}
});
});
logger.Info("Search have been started!");
}
catch (Exception exp)
{
logger.Error(exp, "Search failed. (Outter)");
}
}
示例3: CreateMenuButtons
private ObservableCollection<ScreenMenuItemButton> CreateMenuButtons(ScreenMenuCategory category, int pageNo, string tag)
{
SelectedCategory = category;
var screenMenuItems = AppServices.DataAccessService.GetMenuItems(category, pageNo, tag);
var result = new ObservableCollection<ScreenMenuItemButton>();
var items = screenMenuItems.Select(x => new ScreenMenuItemButton(x, MenuItemCommand, category));
if (category.SortType == 1) items = items.OrderByDescending(x => x.UsageCount);
result.AddRange(items);
return result;
}
示例4: Init
public void Init(Model model) {
InitializeComponent();
OnCompleted += () => {
disposables.Dispose();
};
var availableActions = new ObservableCollection<Action1>();
var includedActions = new ObservableCollection<Action1>();
var applyCommand = new DelegateCommand(
() => {
model.trigger.Configuration.TopicExpression = GetTopicExression();
if (string.IsNullOrEmpty(model.trigger.Configuration.TopicExpression.Any.First().InnerText))
model.trigger.Configuration.TopicExpression = null;
if (string.IsNullOrEmpty(model.trigger.Configuration.ContentExpression.Any.First().InnerText))
model.trigger.Configuration.ContentExpression = null;
model.trigger.Configuration.ActionToken = includedActions.Select(a => a.Token).ToArray();
Success(new Result.Apply(model));
},
() => true
);
applyButton.Command = applyCommand;
var cancelCommand = new DelegateCommand(
() => Success(new Result.Cancel(model)),
() => true
);
cancelButton.Command = cancelCommand;
FixModel(model);
{ // token
valueToken.CreateBinding(TextBlock.TextProperty, model.trigger, x => x.Token);
if (string.IsNullOrEmpty(model.trigger.Token)) {
captionToken.Visibility = Visibility.Collapsed;
valueToken.Visibility = Visibility.Collapsed;
}
}
{ // topic filter
var concreteSetTopics = GetConcreteSetTopics(model.topicSet);
concreteSetTopics.Insert(0, string.Empty);
var topicExpr = model.trigger.Configuration.TopicExpression.Any.First().InnerText;
var topicExprParts = topicExpr.Split(new char[] { '|' });
foreach (var part in topicExprParts) {
var control = CreateTopicExprControl(concreteSetTopics, part);
valuesTopicExpr.Items.Add(control);
}
var addTopicExprPartCommand = new DelegateCommand(
executeMethod: () => {
var control = CreateTopicExprControl(concreteSetTopics, string.Empty);
valuesTopicExpr.Items.Add(control);
},
canExecuteMethod: () => valuesTopicExpr.Items.Count <= 32
);
addTopicExprPartButton.Command = addTopicExprPartCommand;
}
{ // content filter
valueContentExpr.CreateBinding(TextBox.TextProperty, model.trigger.Configuration.ContentExpression
, m => m.Any.First().InnerText
, (m, v) => m.Any = new XmlNode[] { new XmlDocument().CreateTextNode(v) });
}
{ // actions
var addActionCommand = new DelegateCommand(
() => {
var actions = (listAvailableActions.SelectedItems ?? new ArrayList()).Select(i => (Action1)i).ToList();
availableActions.RemoveRange(actions);
includedActions.AddRange(actions);
},
() => (listAvailableActions.SelectedItems ?? new ArrayList()).Count > 0
);
addActionButton.Command = addActionCommand;
var removeActionCommand = new DelegateCommand(
() => {
var actions = (listIncludedActions.SelectedItems ?? new ArrayList()).Select(i => (Action1)i).ToList();
includedActions.RemoveRange(actions);
availableActions.AddRange(actions);
},
() => (listIncludedActions.SelectedItems ?? new ArrayList()).Count > 0
);
removeActionButton.Command = removeActionCommand;
includedActions.AddRange(model.trigger.Configuration.ActionToken.Select(token => model.actions.First(a => a.Token == token)).ToList());
availableActions.AddRange(model.actions.Except(includedActions).ToList());
listAvailableActions.ItemsSource = availableActions;
listIncludedActions.ItemsSource = includedActions;
listIncludedActions.SelectionChanged += delegate { removeActionCommand.RaiseCanExecuteChanged(); };
listAvailableActions.SelectionChanged += delegate { addActionCommand.RaiseCanExecuteChanged(); };
}
Localization();
}
示例5: UpdateFilters
private void UpdateFilters()
{
Log.Debug("Updating filters");
if (_filterSchemes != null)
{
_filterSchemes.Schemes.CollectionChanged -= OnFilterSchemesCollectionChanged;
}
_filterSchemes = _filterSchemeManager.FilterSchemes;
if (_filterSchemes != null)
{
_filterSchemes.Schemes.CollectionChanged += OnFilterSchemesCollectionChanged;
}
var newSchemes = new ObservableCollection<FilterScheme>();
if (RawCollection == null)
{
_targetType = null;
}
else
{
_targetType = CollectionHelper.GetTargetType(RawCollection);
if (_targetType != null)
{
newSchemes.AddRange((from scheme in _filterSchemes.Schemes
where scheme.TargetType != null && _targetType.IsAssignableFromEx(scheme.TargetType)
select scheme));
}
}
newSchemes.Insert(0, NoFilterFilter);
if (AvailableSchemes == null || !Catel.Collections.CollectionHelper.IsEqualTo(AvailableSchemes, newSchemes))
{
AvailableSchemes = newSchemes;
var selectedFilter = _filterService.SelectedFilter ?? NoFilterFilter;
SelectedFilterScheme = selectedFilter;
}
}
示例6: CommpareAdd
private static void CommpareAdd(ObservableCollection<Item> collection, ObservableCompositeCollection<Item> compositeCollection)
{
var data = CreateData();
var stopwatch = Stopwatch.StartNew();
var t1 = stopwatch.Elapsed;
collection.AddRange(data.SelectMany(list => list));
var t2 = stopwatch.Elapsed;
compositeCollection.Content.AddRange(data);
var t3 = stopwatch.Elapsed;
stopwatch.Stop();
var compositeTime = t3 - t2;
var plainTime = t2 - t1;
var factor = compositeTime.TotalSeconds / plainTime.TotalSeconds;
Debug.WriteLine("composite: {0} / plain {1} = {2}", compositeTime, plainTime, factor);
Debug.WriteLine("{0} elements.", compositeCollection.Count);
Assert.IsTrue(factor < 2);
Assert.IsTrue(collection.SequenceEqual(compositeCollection));
}