当前位置: 首页>>代码示例>>C#>>正文


C# ObservableCollection.RemoveAt方法代码示例

本文整理汇总了C#中ObservableCollection.RemoveAt方法的典型用法代码示例。如果您正苦于以下问题:C# ObservableCollection.RemoveAt方法的具体用法?C# ObservableCollection.RemoveAt怎么用?C# ObservableCollection.RemoveAt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ObservableCollection的用法示例。


在下文中一共展示了ObservableCollection.RemoveAt方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Follows_observed_collection

        public void Follows_observed_collection()
        {
            var subject = new ObservableCollection<int>(new[] { 11, 12, 13, 14, 15, 16 });

            var observer = new ObserverCollection<int>();

            observer.Observe(subject);
            EnumerableAssert.AreEqual(subject, observer);

            subject.Insert(3, 77);
            EnumerableAssert.AreEqual(subject, observer);

            subject.Add(21);
            EnumerableAssert.AreEqual(subject, observer);

            subject.RemoveAt(0);
            EnumerableAssert.AreEqual(subject, observer);

            subject.RemoveAt(subject.Count - 1);
            EnumerableAssert.AreEqual(subject, observer);

            subject.Move(3, 0);
            EnumerableAssert.AreEqual(subject, observer);

            subject.Move(1, 5);
            EnumerableAssert.AreEqual(subject, observer);

            subject[4] = 777;
            EnumerableAssert.AreEqual(subject, observer);
        }
开发者ID:jogibear9988,项目名称:ObservableLinq,代码行数:30,代码来源:ObserverCollectionTests.cs

示例2: Remove

            public void Remove(ReferenceHandling referenceHandling)
            {
                var source = new ObservableCollection<int> { 1, 2 };
                var target = new ObservableCollection<int> { 1, 2 };
                using (Synchronize.PropertyValues(source, target, referenceHandling))
                {
                    source.RemoveAt(1);
                    CollectionAssert.AreEqual(new[] { 1 }, source);
                    CollectionAssert.AreEqual(new[] { 1 }, target);

                    source.RemoveAt(0);
                    CollectionAssert.IsEmpty(source);
                    CollectionAssert.IsEmpty(target);
                }
            }
开发者ID:JohanLarsson,项目名称:Gu.State,代码行数:15,代码来源:SynchronizeTests.ObservableCollectionOfInts.cs

示例3: Convert

        public object Convert(object value, Type targetType, object parameter, string language)
        {
            var collection = new ObservableCollection<FilterPivotItem>(((IEnumerable<FilterViewModel>)value).Select<FilterViewModel, FilterPivotItem>(p => CreatePivotItem(p)));

            var notifyCollectionChanged = value as INotifyCollectionChanged;
            if (notifyCollectionChanged != null)
                notifyCollectionChanged.CollectionChanged += (sender, e) =>
                {
                    int index;
                    switch (e.Action)
                    {
                        case NotifyCollectionChangedAction.Add:
                            index = e.NewStartingIndex;
                            foreach (FilterViewModel newItem in e.NewItems)
                                collection.Insert(index++, CreatePivotItem(newItem));
                            break;
                        case NotifyCollectionChangedAction.Remove:
                            index = e.OldStartingIndex;
                            foreach (FilterViewModel oldItem in e.OldItems)
                                collection.RemoveAt(index++);
                            break;
                        default:
                            throw new NotImplementedException();
                    }
                };

            return collection;
        }
开发者ID:JulianMH,项目名称:music-3,代码行数:28,代码来源:FilterViewModelsToPivotItemsConverter.cs

示例4: Test_BindSource_IndexPropertyInt

        public void Test_BindSource_IndexPropertyInt()
        {
            var viewModel = new TestViewModel();
            var bindSource = new BindContext(viewModel, "TestViewModel2.TestViewModel3.IntValues[1]");

            var viewModel2 = new TestViewModel2();
            viewModel.TestViewModel2 = viewModel2;

            var viewModel3 = new TestViewModel3();
            viewModel2.TestViewModel3 = viewModel3;

            Assert.AreEqual(null, bindSource.PropertyType);
            Assert.AreEqual(null, bindSource.Value);

            var list = new ObservableCollection<int>();
            viewModel3.IntValues = list;
            Assert.AreEqual(list, bindSource.Source);
            Assert.AreEqual(typeof(int), bindSource.PropertyType);
            Assert.AreEqual(default(int), bindSource.Value);

            list.Add(1);
            list.Add(2);

            Assert.AreEqual(2, bindSource.Value);

            bindSource.Value = 2;
            Assert.AreEqual(2, list[1]);

            list.RemoveAt(1);

            Assert.AreEqual(default(int), bindSource.Value);
        }
开发者ID:zhouyongh,项目名称:BindingEngine,代码行数:32,代码来源:BindSourceTests.cs

示例5: ObservableCollection_Remove

 public void ObservableCollection_Remove()
 {
     var source = new ObservableCollection<string>() { "A" };
     var snapshot = source.ToLiveLinq().ToObservableEnumerable().Snapshot();
     source.RemoveAt(0);
     snapshot.Value.Should().BeEmpty();
 }
开发者ID:ApocalypticOctopus,项目名称:Apocalyptic.Utilities.Net,代码行数:7,代码来源:ExtensionsTests.StartStopLiveLinq.cs

示例6: ChatViewModel

        public ChatViewModel(Action<string> sendMessageAction)
        {
            MessageCollection = new ObservableCollection<string>();

            var cappedMessageCollection = new ObservableCollection<string>();
            MessageCollection.CollectionChanged += (sender, e) =>
            {
                //Collection will only ever be changed when something is added
                cappedMessageCollection.Add((string)e.NewItems[0]);

                //If capped collection now has more items than allowed by limit,
                if (cappedMessageCollection.Count > MESSAGE_LIMIT) cappedMessageCollection.RemoveAt(0);
            };

            ChatView = CollectionViewSource.GetDefaultView(cappedMessageCollection);

            //Create send message action
            var sendMessageAsync = Command.Create(() => PendingInput.Length > 0, () =>
            {
                sendMessageAction(PendingInput);
                PendingInput = string.Empty;
            });

            //Requery the button CanExecute when PendingInput changes
            this.PropertyChanged += (sender, e) => sendMessageAsync.RequeryCanExecute();

            //Allow for binding to command
            SendMessage = sendMessageAsync;
        }
开发者ID:JLaferri,项目名称:MeleeMatchFinder,代码行数:29,代码来源:ChatViewModel.cs

示例7: Removing_Selected_Should_Select_Next

        public void Removing_Selected_Should_Select_Next()
        {
            var list = new ObservableCollection<TabItem>()
                {
                    new TabItem
                    {
                        Name = "first"
                    },
                    new TabItem
                    {
                        Name = "second"
                    },
                    new TabItem
                    {
                        Name = "3rd"
                    },
                };

            var target = new TabStrip
            {
                Template = new ControlTemplate<TabStrip>(this.CreateTabStripTemplate),
                Items = list
            };

            target.ApplyTemplate();
            target.SelectedTab = list[1];
            Assert.Same(list[1], target.SelectedTab);
            list.RemoveAt(1);

            // Assert for former element [2] now [1] == "3rd"
            Assert.Same(list[1], target.SelectedTab);
            Assert.Same("3rd", target.SelectedTab.Name);
        }
开发者ID:Robertofon,项目名称:Perspex,代码行数:33,代码来源:TabStripTests.cs

示例8: OnNavigatedTo

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            ScrollViewer.SetVerticalScrollMode(MainPageGridView, ScrollMode.Disabled);
            SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Collapsed;
            if (e.NavigationMode != NavigationMode.Back)
            {
                _mainPageViewModel = (MainPageViewModel)Resources["MainPageViewModel"];
                Task.Factory.StartNew(async () =>
                {
                    var navigationItems = await DownloadNavigationItemsAsync();
                    var contentItems = await DownloadContentItemsAsync();
                    var mainContentItems = new ObservableCollection<Content>(contentItems[0].Bundle.Content.OrderByDescending(content => content.PublicationDate));
                    contentItems.RemoveAt(0);
                    var latestContentItems = new ObservableCollection<Row>(contentItems);

                    await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.High,
                        () =>
                        {
                            _mainPageViewModel.NavigationItems = navigationItems;
                            _mainPageViewModel.FirstMainContentItem = mainContentItems[0];
                            mainContentItems.RemoveAt(0);
                            _mainPageViewModel.MainContentItems = mainContentItems;
                            _mainPageViewModel.LatestContentItems = latestContentItems;
                            OpacityRectangle.Visibility = Visibility.Visible;
                            LoadingGrid.Visibility = Visibility.Collapsed;
                            MySplitView.Visibility = Visibility.Visible;
                        }
                        );
                });
            }
            base.OnNavigatedTo(e);
        }
开发者ID:arnvanhoutte,项目名称:DeRedactie,代码行数:32,代码来源:MainPage.xaml.cs

示例9: FromCSV

        public static ObservableCollection<Student> FromCSV()
        {
            studenti = new ObservableCollection<Student>();
            Student student;

            using (var reader = new StreamReader(File.OpenRead("kivnet.csv")))
            {
                while (!reader.EndOfStream)
                {
                    var line = reader.ReadLine();
                    var values = line.Split(';');

                    student = new Student()
                    {
                        Jmeno = values[1].Trim('"'),
                        Prijmeni = values[2].Trim('"'),
                        OsobniCislo = values[0].Trim('"'),
                        TitulPred = values[3].Trim('"'),
                        TitulZa = values[4].Trim('"'),
                        Stav = values[5].Trim('"'),
                        Username = values[6].Trim('"'),
                        Obor = values[17].Trim('"'),
                        Program = values[7].Trim('"')
                    };

                    studenti.Add(student);
                }
            }
            //odstraneni prvni radky
            studenti.RemoveAt(0);

            return studenti;
        }
开发者ID:pivovard,项目名称:ZCU,代码行数:33,代码来源:Loading.cs

示例10: MainWindow

 public MainWindow()
 {
     InitializeComponent();
     ObservableCollection<SpecialColor> cars = new ObservableCollection<SpecialColor>(
         new List<SpecialColor>()
         {
             new SpecialColor{ Name = "Red" },
             //new SpecialColor{ Name = "Green" },
             //new SpecialColor { Name = "Blue" }
         });
     cmbColors.ItemsSource = cars;
     cmbColors.SelectedIndex = 0;
     cars.Add(new SpecialColor { Name = "Black" });
     cars.RemoveAt(0);
     cars.RemoveAt(0); // Remove last car from the combobox
 }
开发者ID:wordtinker,项目名称:c-sharp,代码行数:16,代码来源:MainWindow.xaml.cs

示例11: _timer_Tick

        private void _timer_Tick(object sender, object e)
        {
            Task.Factory.StartNew(async () =>
            {
                var navigationItems = await DownloadNavigationItemsAsync();
                var contentItems = await DownloadContentItemsAsync();
                var mainContentItems = new ObservableCollection<Content>(contentItems[0].Bundle.Content.OrderByDescending(content => content.PublicationDate));
                contentItems.RemoveAt(0);
                var latestContentItems = new ObservableCollection<Row>(contentItems);

                await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.High,
                    () =>
                    {
                        _mainPageViewModel.NavigationItems = navigationItems;
                        _mainPageViewModel.FirstMainContentItem = mainContentItems[0];
                        mainContentItems.RemoveAt(0);
                        _mainPageViewModel.MainContentItems = mainContentItems;
                        _mainPageViewModel.LatestContentItems = latestContentItems;
                        OpacityRectangle.Visibility = Visibility.Visible;
                        LoadingGrid.Visibility = Visibility.Collapsed;
                        MySplitView.Visibility = Visibility.Visible;
                    }
                );
            });
        }
开发者ID:arnvanhoutte,项目名称:DeRedactie,代码行数:25,代码来源:MainPage.xaml.cs

示例12: MoveToEnd

 public static void MoveToEnd(ObservableCollection<Article> fromList,
     ObservableCollection<Article> toList,int indexFrom)
 {
     if(indexFrom!=-1) {
         toList.Add(fromList[indexFrom]);
         fromList.RemoveAt(indexFrom);
     }
 }
开发者ID:pszczesz,项目名称:sklepik2015,代码行数:8,代码来源:ListBoxMove.cs

示例13: TestAddAndRemoveItems

		public void TestAddAndRemoveItems()
		{
			ChartPlotter plotter = new ChartPlotter();
			plotter.PerformLoad();

			DevMarkerChart chart = new DevMarkerChart();
			chart.MarkerBuilder = new EllipseMarker();

			plotter.Children.Add(chart);

			ObservableCollection<Point> source = new ObservableCollection<Point>();
			chart.ItemsSource = source;

			const int count = 10;

			// stage 1
			for (int i = 0; i < count; i++)
			{
				source.Add(new Point());
				Assert.AreEqual(source.Count, chart.Items.Count);
			}

			for (int i = count - 1; i >= 0; i--)
			{
				source.RemoveAt(i);
				Assert.AreEqual(source.Count, chart.Items.Count);
			}


			// stage 2
			for (int i = 0; i < count; i++)
			{
				source.Add(new Point());
				Assert.AreEqual(source.Count, chart.Items.Count);
			}

			Random rnd = new Random();
			for (int i = count - 1; i >= 0; i--)
			{
				int index = rnd.Next(0, source.Count - 1);
				source.RemoveAt(index);
				Assert.AreEqual(source.Count, chart.Items.Count);
			}

			// todo check that all items are visible
		}
开发者ID:modulexcite,项目名称:DynamicDataDisplay,代码行数:46,代码来源:DevMarkerChartTest.cs

示例14: MoveAt

 public static void MoveAt(ObservableCollection<Article> fromList,
     ObservableCollection<Article> toList,int indexFrom,int indexTo)
 {
     if(indexFrom!=-1) {
             toList.Insert(indexTo,fromList[indexFrom]);
             fromList.RemoveAt(indexFrom);
         }
 }
开发者ID:pszczesz,项目名称:sklepik2015,代码行数:8,代码来源:ListBoxMove.cs

示例15: Select_Is_Updated_On_Remove

 public void Select_Is_Updated_On_Remove()
 {
     var subject = new ObservableCollection<int>(new [] { 0, 1, 2, 3, 4, 5, 6, 7 });
     var result = subject.ToQueryable().Select(i => i * 2).ToObservable();
     subject.Remove(5);
     Assert.AreEqual(12, result[5]);
     subject.RemoveAt(5);
     Assert.AreEqual(14, result[5]);
 }
开发者ID:TheFabFab,项目名称:ObservableLinq,代码行数:9,代码来源:SelectTests.cs


注:本文中的ObservableCollection.RemoveAt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。