Ejemplo n.º 1
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()
                });
            }
        }