Ejemplo n.º 1
0
 private void AlterModel(ObservableCollection <ListObjectModel> obj)
 {
     TestCollection.Clear();
     foreach (var a in obj)
     {
         TestCollection.Add(a.Clone() as ListObjectModel);
     }
 }
Ejemplo n.º 2
0
        public TestViewModel(bool dontCreateCollection = false)
        {
            Add = new RelayCommand((k) => {
                TestCollection.Add(new TestViewModel(true)
                {
                    FirstName = "Added item", LastName = new Random().Next(1, 999).ToString()
                });
            });
            BackgroundAdd = new RelayCommand((k) => {
                Thread t = new Thread(() => {
                    TestCollection.Add(new TestViewModel(true)
                    {
                        FirstName = "Added item in another thread!", LastName = new Random().Next(1, 999).ToString()
                    });
                });
                t.IsBackground = true;
                t.Start();
            });
            Move = new RelayCommand((k) => {
                TestCollection.FastMove(TestCollection.Count - 1, 0);
            });
            BackgroundMove = new RelayCommand((k) => {
                //Thread t = new Thread(() => {
                //    TestCollection.FastMove(TestCollection.Count - 1, 0);
                //});
                //t.IsBackground = true;
                //t.Start();
                MoveBkg();
            });
            DeleteLast = new RelayCommand((k) => {
                TestCollection.Remove(TestCollection.Last());
            });
            Clear = new RelayCommand((k) => {
                TestCollection.Clear();
            });

            if (dontCreateCollection)
            {
                return;
            }
            TestCollection = new ThreadSafeObservableCollection <TestViewModel>();
            while (TestCollection.Count < 7)
            {
                TestCollection.Add(new TestViewModel(true)
                {
                    FirstName = "Item", LastName = TestCollection.Count.ToString()
                });
            }
        }
Ejemplo n.º 3
0
            IEnumerator AddToCollection()
            {
                while (true)
                {
                    var toRemove = new DataModel()
                    {
                        message = "I'm going to get removed",
                        color   = Random.ColorHSV()
                    };

                    var toStay = new DataModel()
                    {
                        message = "I'm going to stay",
                        color   = Random.ColorHSV()
                    };

                    var toChange = new DataModel()
                    {
                        message = "I'm Going to Change",
                        color   = Random.ColorHSV()
                    };


                    TestCollection.Add(toRemove);
                    TestCollection.Add(toStay);
                    TestCollection.Add(toChange);

                    yield return(new WaitForSeconds(2f));

                    TestCollection.Remove(toRemove);
                    TestCollection[TestCollection.IndexOf(toChange)] = new DataModel()
                    {
                        message = "Told ya ;)",
                        color   = Random.ColorHSV()
                    };

                    yield return(new WaitForSeconds(2f));

                    if (TestCollection.Count > 5)
                    {
                        TestCollection.Clear();
                    }
                }
            }