本文整理汇总了C#中ObservableList类的典型用法代码示例。如果您正苦于以下问题:C# ObservableList类的具体用法?C# ObservableList怎么用?C# ObservableList使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ObservableList类属于命名空间,在下文中一共展示了ObservableList类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LocationsTreeViewModel
public LocationsTreeViewModel(ObservableCollection<Location> locations)
{
Locations = new ObservableList<LocationNode>();
foreach (var location in locations) Locations.Add(new LocationNode(location));
locations.CollectionChanged += (s, e) =>
{
switch (e.Action)
{
case NotifyCollectionChangedAction.Add:
foreach (Location location in e.NewItems) Locations.Add(new LocationNode(location));
break;
case NotifyCollectionChangedAction.Remove:
foreach (Location location in e.OldItems)
{
var item = Locations.FirstOrDefault(l => l.Location.Guid == location.Guid);
if (item != null) Locations.Remove(item);
}
break;
case NotifyCollectionChangedAction.Replace:
foreach (Location location in e.OldItems)
{
var item = Locations.FirstOrDefault(l => l.Location.Guid == location.Guid);
if (item != null) Locations.Remove(item);
}
foreach (Location location in e.NewItems) Locations.Add(new LocationNode(location));
break;
case NotifyCollectionChangedAction.Reset:
Locations.Clear();
foreach (Location location in e.NewItems) Locations.Add(new LocationNode(location));
break;
}
};
LocationsTreeViewSource = new CollectionViewSource { Source = Locations };
LocationsTreeViewSource.SortDescriptions.Add(new SortDescription("Location.Name", ListSortDirection.Ascending));
}
示例2: object
private object _busysem = new object(); // semaphore
#endregion Fields
#region Constructors
public SerialConnTest()
{
ADCValues = new ObservableList<VoltPoint>();
Connection = (Application.Current as App).CurrentSerialConnection;
RCUCom = new RCUCommunication(Connection);
RCUCom.ProgressChanged += RaiseProgressChanged;
}
示例3: TestAddRange
public void TestAddRange()
{
var list = new List<string> { "aaa", "bbb", "ccc" };
var set = new ObservableList<string>(list);
Assert.AreEqual(set.Count, list.Count);
bool propertyChangedInvoked = false;
bool collectionChangedInvoked = false;
set.PropertyChanged += (sender, e) =>
{
Assert.AreEqual(e.PropertyName, nameof(ObservableList<string>.Count));
propertyChangedInvoked = true;
};
set.CollectionChanged += (sender, e) =>
{
Assert.AreEqual(e.Action, NotifyCollectionChangedAction.Add);
Assert.AreEqual(e.NewStartingIndex, 3);
Assert.NotNull(e.NewItems);
Assert.AreEqual(e.NewItems.Count, 2);
Assert.AreEqual(e.NewItems[0], "ddd");
Assert.AreEqual(e.NewItems[1], "eee");
collectionChangedInvoked = true;
};
set.AddRange(new[] { "ddd", "eee" });
Assert.AreEqual(set.Count, 5);
Assert.AreEqual(set[0], "aaa");
Assert.AreEqual(set[1], "bbb");
Assert.AreEqual(set[2], "ccc");
Assert.AreEqual(set[3], "ddd");
Assert.AreEqual(set[4], "eee");
Assert.True(propertyChangedInvoked);
Assert.True(collectionChangedInvoked);
}
示例4: AddRange_FiresCollectionChanged
public void AddRange_FiresCollectionChanged()
{
var list = new ObservableList<int> { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
int eventFireCount = 0;
list.CollectionChanged += (sender, args) =>
{
eventFireCount++;
Assert.AreEqual(NotifyCollectionChangedAction.Add, args.Action);
switch (eventFireCount)
{
case 1:
Assert.AreEqual(9, args.NewStartingIndex);
Assert.IsTrue(new[] { 10 }.SequenceEqual(args.NewItems.Cast<int>()));
break;
case 2:
Assert.AreEqual(10, args.NewStartingIndex);
Assert.IsTrue(new[] { 11 }.SequenceEqual(args.NewItems.Cast<int>()));
break;
}
};
list.AddRange(new[] { 10, 11 });
}
示例5: OnReportingCompleted
private void OnReportingCompleted(ObservableList<PendingReport>.ListChangedEventArgs e, ResultCompletionEventArgs args)
{
if (e.Item.ReportCompletedCallback != null)
{
e.Item.ReportCompletedCallback(e.Item.Exception, args.WasCancelled);
}
}
示例6: SoftphoneEngine
public SoftphoneEngine()
{
_sync = new object();
// set license here
PhoneLines = new ObservableList<IPhoneLine>();
PhoneCalls = new ObservableList<IPhoneCall>();
LogEntries = new ObservableList<LogEntry>();
InstantMessages = new ObservableList<string>();
CallHistory = new CallHistory();
CallTypes = new List<CallType> { CallType.Audio, CallType.AudioVideo };
// enable file logging
InitLogger();
// create softphone
MinPort = 20000;
MaxPort = 20500;
//LocalIP = SoftPhoneFactory.GetLocalIP();
InitSoftphone(false);
// create media
MediaHandlers = new MediaHandlers();
MediaHandlers.Init();
}
示例7: CanAccumulate
public void CanAccumulate()
{
var items = new ObservableList<Person>();
var subscription = items.Changes
.Subscribe(changes =>
{
Console.WriteLine(changes);
});
using (var x = items.SuspendNotifications())
{
foreach (var person in _random.Take(20000))
{
items.Add(person);
}
items.Clear();
var result = items.GetChanges();
items[10] = new Person("Roland", 1);
}
}
示例8: CanHaveManyComputeds
public void CanHaveManyComputeds()
{
var prefix = new Observable<string>("Before");
var contacts = new ObservableList<Contact>(
Enumerable.Range(0, 10000)
.Select(i => new Contact()
{
FirstName = "FirstName" + i,
LastName = "LastName" + i
}));
var projections = new ComputedList<Projection>(() =>
from c in contacts
select new Projection(prefix, c));
string dummy;
foreach (var projection in projections)
dummy = projection.Name;
Assert.AreEqual("BeforeFirstName3LastName3", projections.ElementAt(3).Name);
prefix.Value = "After";
foreach (var projection in projections)
dummy = projection.Name;
Assert.AreEqual("AfterFirstName3LastName3", projections.ElementAt(3).Name);
}
示例9: TagLineListForm
public TagLineListForm(IServiceProvider provider, IEnumerable<TagLineInfo> tagLines)
{
if (provider == null)
throw new ArgumentNullException(nameof(provider));
if (tagLines == null)
throw new ArgumentNullException(nameof(tagLines));
_serviceManager = new ServiceContainer(provider);
_tagLines = new ObservableList<TagLineInfo>(tagLines);
InitializeComponent();
_serviceManager.Publish<ITagLineListFormService>(new TagLineListFormService(this));
_serviceManager.Publish<IDefaultCommandService>(new DefaultCommandService("Janus.Forum.TagLine.Edit"));
_toolbarGenerator = new StripMenuGenerator(_serviceManager, _toolStrip, "Forum.TagLine.Toolbar");
_contextMenuGenerator = new StripMenuGenerator(_serviceManager, _contextMenuStrip, "Forum.TagLine.ContextMenu");
_listImages.Images.Add(
_serviceManager.GetRequiredService<IStyleImageManager>()
.GetImage(@"MessageTree\Msg", StyleImageType.ConstSize));
UpdateData();
_tagLines.Changed += (sender, e) => UpdateData();
}
示例10: FilteredPhotoModel
public FilteredPhotoModel(Windows.Storage.StorageFile file, ObservableList<Filter> filters)
{
_photo = new PhotoModel(file);
Filters = filters;
Filters.ItemsChanged += Filters_ItemsChanged;
}
示例11: Project
public Project()
{
// Default projects
details = new ProjectDetails ();
buttons = new ObservableList <ButtonProjectElement> ();
elements = new List <ProjectElement> ();
}
示例12: AddRangeNotifiesAsResetInsteadOfIndividualItemsWhenItemCountAboveThresholdTest
public void AddRangeNotifiesAsResetInsteadOfIndividualItemsWhenItemCountAboveThresholdTest(int lowerLimit, int upperLimit)
{
// given
var rangeToAdd = Enumerable.Range(lowerLimit, upperLimit - lowerLimit + 1).ToList();
var testScheduler = new TestScheduler();
var testObserverCollectionChanges = testScheduler.CreateObserver<IObservableCollectionChange<int>>();
var testObserverResets = testScheduler.CreateObserver<Unit>();
using (var observableList = new ObservableList<int>())
{
// when
observableList.ThresholdAmountWhenChangesAreNotifiedAsReset = 0;
observableList.CollectionChanges.Subscribe(testObserverCollectionChanges);
observableList.Resets.Subscribe(testObserverResets);
testScheduler.Schedule(TimeSpan.FromTicks(100), () => { observableList.AddRange(rangeToAdd); });
testScheduler.Start();
// then
var shouldBeReset = rangeToAdd.Count >= observableList.ThresholdAmountWhenChangesAreNotifiedAsReset;
testObserverCollectionChanges.Messages.Count.Should().Be(shouldBeReset ? 1 : rangeToAdd.Count);
testObserverCollectionChanges.Messages.Should()
.Match(recordedMessages =>
recordedMessages.All(message => message.Value.Value.ChangeType == (shouldBeReset ? ObservableCollectionChangeType.Reset : ObservableCollectionChangeType.ItemAdded)));
testObserverResets.Messages.Count.Should().Be(shouldBeReset ? 1 : 0);
}
}
示例13: Data2Country
ObservableList<TreeNode<ITreeViewSampleItem>> Data2Country(List<TreeViewSampleDataCountry> data)
{
var countries = new ObservableList<TreeNode<ITreeViewSampleItem>>();
data.ForEach(x => countries.Add(Node(new TreeViewSampleItemCountry(x.Name, x.Flag))));
return countries;
}
示例14: AddHousesListListeners
private void AddHousesListListeners(ObservableList<House> child)
{
if (child == null)
return;
var notifyPropertyChanging = child as INotifyPropertyChanging;
// ReSharper disable ConditionIsAlwaysTrueOrFalse
if (notifyPropertyChanging != null)
// ReSharper restore ConditionIsAlwaysTrueOrFalse
notifyPropertyChanging.PropertyChanging += HousesListPropertyChangingEventHandler;
var notifyPropertyChanged = child as INotifyPropertyChanged;
// ReSharper disable ConditionIsAlwaysTrueOrFalse
if (notifyPropertyChanged != null)
// ReSharper restore ConditionIsAlwaysTrueOrFalse
notifyPropertyChanged.PropertyChanged += HousesListPropertyChangedEventHandler;
var notifyChildPropertyChanged = child as INotifyCollectionChanged;
// ReSharper disable ConditionIsAlwaysTrueOrFalse
if (notifyChildPropertyChanged != null)
// ReSharper restore ConditionIsAlwaysTrueOrFalse
notifyChildPropertyChanged.CollectionChanged += HousesListChangedEventHandler;
foreach (var item in child)
AddHousesItemListeners(item);
}
示例15: ListCollectionView
public ListCollectionView (IList collection)
: base (collection)
{
var interfaces = SourceCollection.GetType ().GetInterfaces ();
foreach (var t in interfaces) {
if (t.IsGenericType && t.GetGenericTypeDefinition () == typeof (IList<>)) {
Type type = t.GetGenericArguments () [0];
ItemConstructor = type.GetConstructor (Type.EmptyTypes);
}
}
UpdateCanAddNewAndRemove ();
filteredList = new ObservableList<object> ();
RootGroup = new RootCollectionViewGroup (null, null, 0, false, SortDescriptions);
CurrentPosition = -1;
IsEmpty = ActiveList.Count == 0;
MoveCurrentToPosition (0);
if (SourceCollection is INotifyCollectionChanged)
((INotifyCollectionChanged) SourceCollection).CollectionChanged += HandleSourceCollectionChanged;
GroupDescriptions.CollectionChanged += (o, e) => Refresh ();
((INotifyCollectionChanged) SortDescriptions).CollectionChanged += (o, e) => {
if (IsAddingNew || IsEditingItem)
throw new InvalidOperationException ("Cannot modify SortDescriptions while adding or editing an item");
Refresh ();
};
filteredList.CollectionChanged += HandleFilteredListCollectionChanged;
RootGroup.CollectionChanged += HandleRootGroupCollectionChanged;
}