本文整理汇总了C#中ObservableCollection.Clear方法的典型用法代码示例。如果您正苦于以下问题:C# ObservableCollection.Clear方法的具体用法?C# ObservableCollection.Clear怎么用?C# ObservableCollection.Clear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ObservableCollection
的用法示例。
在下文中一共展示了ObservableCollection.Clear方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InputViewModel
public InputViewModel(string prompt, string defaultInputValue, IEnumerable<string> options, RelayCommand<string> dismissed)
{
Options = new ObservableCollection<string>(options);
SearchOptions = new ObservableCollection<string>();
Dismissed = dismissed;
SearchHelper = new SearchHelper(() =>
{
SearchOptions.Clear();
foreach (var option in Options)
SearchOptions.Add(option);
},
(searchString) =>
{
var lowerCaseSearch = searchString.ToLower();
var filteredOptions = Options.Where(str => str.ToLower().Contains(searchString) || lowerCaseSearch.Contains(str.ToLower())).ToList();
var existingSearch = SearchOptions.ToList();
foreach (var option in existingSearch)
{
if (filteredOptions.Contains(option))
filteredOptions.Remove(option);
else
SearchOptions.Remove(option);
}
foreach (var option in filteredOptions)
SearchOptions.Add(option);
}, 1, "`", 0);
Prompt = prompt;
InputValue = defaultInputValue;
//clear it so we dont start with any search populated
SearchOptions.Clear();
}
示例2: VolunteerPlanVM
public VolunteerPlanVM()
{
db = new Database(Database.connectStr);
Dic_Unfinish = new Dictionary<string, ObservableCollection<RecyclePlanModel>>();
ListPlan_Un = new ObservableCollection<string>();
ListUser_Un = new ObservableCollection<RecyclePlanModel>();
foreach (VolunteerPlanTable plan in db.VolunteerPlans.Where(c => c.IsFinish == false))
{
ListUser_Un.Clear();
foreach (VolunteerPlanShipTable ship in db.VolunteerPlanShips.Where(c => c.PlanId == plan.Id))
{
RecyclePlanModel model = new RecyclePlanModel()
{
UserName = db.Users.Single(c => c.Id == ship.UserId).UserName,
Address = db.Users.Single(c => c.Id == ship.UserId).Address,
IsFinish = plan.IsFinish,
IsCheck = ship.IsCheck,
UserId = ship.UserId,
ShipId = ship.Id,
};
ListUser_Un.Add(model);
}
if (!Dic_Unfinish.Keys.Contains(plan.Time))
Dic_Unfinish.Add(plan.Time, ListUser_Un);
else
{
Dic_Unfinish.Add(plan.Time + " ", ListUser_Un);
}
}
foreach (VolunteerPlanTable plan in db.VolunteerPlans.Where(c => c.IsFinish == true))
{
ListUser_Un.Clear();
foreach (VolunteerPlanShipTable ship in db.VolunteerPlanShips.Where(c => c.PlanId == plan.Id))
{
RecyclePlanModel model = new RecyclePlanModel()
{
UserName = db.Users.Single(c => c.Id == ship.UserId).UserName,
Address = db.Users.Single(c => c.Id == ship.UserId).Address,
IsFinish = plan.IsFinish,
IsCheck = ship.IsCheck,
UserId = ship.UserId,
ShipId = ship.Id,
};
ListUser_Un.Add(model);
}
if (!Dic_Unfinish.Keys.Contains(plan.Time))
Dic_Unfinish.Add(plan.Time, ListUser_Un);
else
{
Dic_Unfinish.Add(plan.Time + " ", ListUser_Un);
}
}
}
示例3: FriendsListVM
public FriendsListVM()
{
Friends = new ObservableCollection<Friend>();
Random Rnd = new Random(DateTime.Now.Millisecond);
for (int i = 0; i < 50; i++ )
Friends.Add(new Friend() { Name = "John", ID = Rnd.Next(1, 10000000).ToString() });
_AllFriends = new SimpleCommand<object>
(
new Action<object>
(
(Arg) =>
{
Friends.Clear();
for (int i = 0; i < 50; i++)
Friends.Add(new Friend() { Name = "John", ID = Rnd.Next(1, 10000000).ToString() });
}
)
);
_Nearby = new SimpleCommand<object>
(
new Action<object>
(
(Arg) =>
{
Friends.Clear();
for (int i = 0; i < 3; i++)
Friends.Add(new Friend() { Name = "Richard Jacquier", ID = Rnd.Next(1, 10000000).ToString() });
}
)
);
_Online = new SimpleCommand<object>
(
new Action<object>
(
(Arg) =>
{
Friends.Clear();
for (int i = 0; i < 10; i++)
Friends.Add(new Friend() { Name = "Ian Atkin", ID = Rnd.Next(1, 10000000).ToString() });
}
)
);
}
示例4: MipsDebuggerViewModel
public MipsDebuggerViewModel(MachineViewModel machineVM)
: base(machineVM)
{
m_Debugger = new MipsDebugger();
Disassembly = new ObservableCollection<DisassembledInstruction>();
WeakEventManager<MipsDebugger, EventArgs>.AddHandler(
m_Debugger,
"CodeScanned",
(o, e) =>
{
Dispatcher.InvokeAsync(() =>
{
Disassembly.Clear();
foreach (var l in m_Debugger.Disassembly)
{
Disassembly.Add(l);
}
Dispatcher.InvokeAsync(() =>
{
var e1 = Finished;
if (e1 != null)
e1(this, new EventArgs());
}, DispatcherPriority.Render);
});
});
}
示例5: ExecutionViewModel
public ExecutionViewModel()
{
Tasks = new ObservableCollection<Tuple<PandocTask, PandocTaskResult>>();
Do = new RelayCommand(() =>
{
if (IsBusy) return;
IsBusy = true;
Task.Factory.StartNew(() =>
{
App.Current.Dispatcher.Invoke(() =>
{
Tasks.Clear();
});
var tasks = TaskRepository.GetAll();
PandocRunner.Run(this.GetLocator().Config.Model.PandocExePath, tasks, (task, result) =>
{
App.Current.Dispatcher.Invoke(() =>
{
this.GetLocator().Execution.Tasks.Add(new Tuple<PandocTask, PandocTaskResult>(task, result));
});
});
}).ContinueWith(task => IsBusy = false);
});
}
示例6: loadDBPosition
public void loadDBPosition(string position)
{
this.instPositionWrapperVMList_ = new ObservableCollection<InstPositionWrapperVM>();
RiskMonitor.PositionSingletonManger.setReferenceDate(this.ReferenceDate_);
//db 만들어서 관리 해야함? ㅇㅇ 그래야함 ㅡ.ㅡㅋ
instPositionWrapperVMList_.Clear();
DataBaseManager loader = new DataBaseManager();
loader.PositionHostInfo_ = new PositionHostInfo(position);
List<InstPositionInfo> instDataList = loader.loadPositionData();
foreach (InstPositionInfo item in instDataList)
{
InstUriInfo instUri = PositionSingletonManger.CreateInstUriInfo(item.InstCode_, item.InstType_);
//ResultUriInfo resultUri = CreateResultUriInfo(item.InstCode_, item.InstType_);
//InstrumentBaseViewModel instBaseVM = InstrumentBaseViewModel.CreateInstBaseVM(instUri, resultUri);
InstrumentBaseViewModel instBaseVM = InstrumentBaseViewModel.CreateInstBaseVM(instUri);
instBaseVM.ReferenceDate_ = PositionSingletonManger.referenceDate();
InstPositionWrapperVM viewModel = new InstPositionWrapperVM(item, instBaseVM);
instPositionWrapperVMList_.Add(viewModel);
}
}
示例7: GetNews
public static void GetNews(string category, ObservableCollection<NewsItem> newsItemList)
{
var allitems = getNewsItem(); //get all news items
var filteredItem = allitems.Where(p => p.Category == category).ToList(); // filter down to news items belonging to a specific category.
newsItemList.Clear();
filteredItem.ForEach(p => newsItemList.Add(p)); // add each filtered item to the observable collection.
}
示例8: Should_fire_for_collection_clear
public void Should_fire_for_collection_clear()
{
var ppl = new ObservableCollection<Person> { new Person() };
Tracker.Track(ppl);
ppl.Clear();
Assert.IsTrue(HasChange);
}
示例9: MusicViewModel
public MusicViewModel(string fileLocation, string musicLocation, string musicDestination, long maximumSpace,
int maximumNumberOfSongs)
{
StorageFileLocation = fileLocation;
MusicLocation = musicLocation;
MusicDestination = musicDestination;
MaximumSpace = maximumSpace;
MaximumNumberOfSongs = maximumNumberOfSongs;
MusicCollection = new ObservableCollection<MusicEntry>();
_saveMusic = new SaveMusicCommand();
_copyMusic = new CopyMusicCommand();
SelectCommand = new RelayCommand(async () =>
{
Busy = true;
var task = new SelectMusicTask(_musicCollection, 99);
task.EntryAdded += EntryAdded;
Busy = await task.Execute();
}, () => !Busy);
ReloadCommand = new RelayCommand(() =>
{
_mp3Done = false;
_wmaDone = false;
Busy = true;
var task = new LoadMusicTask(@"e:\various");
task.LoadMusicEvent += LoadMusicEvent;
MusicCollection.Clear();
task.Execute();
}, () => !Busy);
}
示例10: HandleCollectionChanges
private void HandleCollectionChanges(Client client, NotifyCollectionChangedEventArgs args, ObservableCollection<Interlocutor> actualCollection, ObservableCollection<object> nullCollection)
{
if (actualCollection.Count == 0)
{
nullCollection.Clear();
nullCollection.Add(new NullInterlocutor(client));
return;
}
var nullInterlocutor = nullCollection.OfType<NullInterlocutor>().FirstOrDefault();
if (nullInterlocutor != null)
{
nullCollection.Remove(nullInterlocutor);
}
if (args.OldItems != null)
{
foreach (var oldItem in args.OldItems)
{
nullCollection.Remove(oldItem);
}
}
if (args.NewItems != null)
{
foreach (var newItem in args.NewItems)
{
nullCollection.Insert(actualCollection.IndexOf((Interlocutor) newItem), newItem);
}
}
}
示例11: LoadTwitterFeedIntoListBox
internal static void LoadTwitterFeedIntoListBox(ObservableCollection<Tweet> Items, string url)
{
DispatcherHelper.CheckBeginInvokeOnUI(() => Items.Clear());
WebClient client = new WebClient();
client.DownloadStringCompleted += (sender, args) =>
{
if (args.Error == null)
{
var xml = args.Result;
if (xml.Length == 0)
return;
XDocument doc = XDocument.Parse(xml);
var tweets = from item in doc.Root.Element("channel").Elements("item")
select new Tweet
{
Message = item.Element("title").Value,
Permalink = item.Element("link").Value,
PublishDate = item.Element("pubDate").Value.ParseDateTime(),
UserName = "",
};
DispatcherHelper.CheckBeginInvokeOnUI(() =>
{
foreach (var tweet in tweets)
{
Items.Add(tweet);
}
});
}
else
{
Messenger.Default.Send<ErrorMessage>(new ErrorMessage(args.Error));
}
};
client.DownloadStringAsync(new Uri(url, UriKind.Absolute));
}
示例12: IssueListViewModel
public IssueListViewModel()
{
Issues = new ObservableCollection<Issue> ();
var canRefresh = this.WhenAny (x => x.IsBusy, x => !x.Value);
Refresh = ReactiveCommand.CreateAsyncTask<IssueList> (canRefresh, async _ => {
IsBusy = true;
var issues = await LoadIssues.ExecuteAsync ();
IsBusy = false;
return issues;
});
ItemTapped = ReactiveCommand.Create ();
LoadIssues = ReactiveCommand.CreateAsyncTask (async _ => {
var api = RestService.For<IIssuesApi> ("http://localhost:3000/api");
var issues = await api.GetIssues ();
return issues;
});
LoadIssues.Subscribe (x => {
Issues.Clear ();
foreach (var i in x.issues) {
Issues.Add (i);
}
});
LoadIssues.ThrownExceptions.Subscribe (ex => UserError.Throw ("Couldn't load issues", ex));
BlobCache.UserAccount.GetObject<string> ("email")
.Where (x => !String.IsNullOrWhiteSpace (x))
.InvokeCommand (this, x => x.LoadIssues);
}
示例13: ExecuteOnAdd
public void ExecuteOnAdd(ObservableCollection<AppearListViewItemModel> dataList)
{
CommonLightBox dialog = new CommonLightBox();
TagsSelectorView selectorView = new TagsSelectorView();
var tagSelectorViewModel = new TagSelectorViewModel();
SetSelectingTags(tagSelectorViewModel.SelectingTags);
selectorView.SetModel(tagSelectorViewModel);
dialog.Owner = Application.Current.MainWindow;
dialog.BindUIElement(selectorView);
dialog.LightBoxKind = CommonLightBox.CommonLightBoxKind.SaveCancel;
dialog.IsStretchable = false;
selectorView.Height = Application.Current.MainWindow.ActualHeight - 80;
selectorView.Width = Application.Current.MainWindow.ActualWidth - 80;
selectorView.DataContext = tagSelectorViewModel;
if (ShowDialogManager.ShowDialog(dialog) == true)
{
tagSelectorViewModel.UpdateModelsComposite();
_stickable.SetTagIds(GetSelectingTagIds(tagSelectorViewModel.SelectingTags));
dataList.Clear();
var list = TagToAppearListViewModelConverter.ToAppearListViewItemModel(_stickable.GetTagIds(), _tagManager);
foreach (var newItemModel in list)
{
dataList.Add(newItemModel);
}
}
}
示例14: AlertsModel
public AlertsModel()
{
Alerts = new ObservableCollection<AlertProxy>();
UnobservedAlerts = new ObservableCollection<AlertProxy>();
ServerAlerts = new ObservableCollection<Alert>();
ShowObserved = new Observable<bool>();
AlertsToSee = Alerts;
ShowObserved.PropertyChanged += (sender, args) =>
{
AlertsToSee = ShowObserved.Value ? Alerts : UnobservedAlerts;
OnPropertyChanged(() => AlertsToSee);
};
ServerAlerts.CollectionChanged += (sender, args) =>
{
Alerts.Clear();
foreach (var serverAlert in ServerAlerts)
{
Alerts.Add(new AlertProxy(serverAlert));
}
};
ShowObserved.Value = false;
Alerts.CollectionChanged += (sender, args) => UpdateUnobserved();
GetAlertsFromServer();
OnPropertyChanged(() => Alerts);
}
示例15: ObservableCollection_Clear
public void ObservableCollection_Clear()
{
var source = new ObservableCollection<string>() { "A", "B", "C" };
var snapshot = source.ToLiveLinq().ToObservableEnumerable().Snapshot();
source.Clear();
snapshot.Value.Should().BeEmpty();
}
开发者ID:ApocalypticOctopus,项目名称:Apocalyptic.Utilities.Net,代码行数:7,代码来源:ExtensionsTests.StartStopLiveLinq.cs