public void BindItemsSource()
        {
            // Create the original DataContext object
            StringsContainer stringsContainer1 = new StringsContainer();
            stringsContainer1.Strings = new ObservableCollection<string> { "first", "second", "third" };

            // Create the next object to be used as DataContext
            StringsContainer stringsContainer2 = new StringsContainer();
            stringsContainer2.Strings = new ObservableCollection<string> { "one", "two", "three", "four", "five" };

            // Create the DataGrid and setup its binding
            DataGrid dataGrid = new DataGrid();
            dataGrid.DataContext = stringsContainer1;
            Binding binding = new Binding("Strings");
            binding.Mode = BindingMode.OneWay;
            dataGrid.SetBinding(DataGrid.ItemsSourceProperty, binding);
            TestPanel.Children.Add(dataGrid);

            this.EnqueueCallback(delegate
            {
                Assert.AreEqual(stringsContainer1.Strings, dataGrid.ItemsSource, "ItemsSource was not set from the original DataContext");
                Assert.AreEqual(3, dataGrid.DataConnection.Count, "ItemsSource was not set from the original DataContext");
                dataGrid.DataContext = stringsContainer2;
            });
            this.EnqueueYieldThread();

            this.EnqueueCallback(delegate
            {
                Assert.AreEqual(stringsContainer2.Strings, dataGrid.ItemsSource, "ItemsSource did not change along with the DataContext");
                Assert.AreEqual(5, dataGrid.DataConnection.Count, "ItemsSource did not change along with the DataContext");
            });
            this.EnqueueTestComplete();
        }
        public void BindItemsSource()
        {
            // Create the original DataContext object
            StringsContainer stringsContainer1 = new StringsContainer();

            stringsContainer1.Strings = new ObservableCollection <string> {
                "first", "second", "third"
            };

            // Create the next object to be used as DataContext
            StringsContainer stringsContainer2 = new StringsContainer();

            stringsContainer2.Strings = new ObservableCollection <string> {
                "one", "two", "three", "four", "five"
            };

            // Create the DataGrid and setup its binding
            DataGrid dataGrid = new DataGrid();

            dataGrid.DataContext = stringsContainer1;
            Binding binding = new Binding("Strings");

            binding.Mode = BindingMode.OneWay;
            dataGrid.SetBinding(DataGrid.ItemsSourceProperty, binding);
            TestPanel.Children.Add(dataGrid);

            this.EnqueueCallback(delegate
            {
                Assert.AreEqual(stringsContainer1.Strings, dataGrid.ItemsSource, "ItemsSource was not set from the original DataContext");
                Assert.AreEqual(3, dataGrid.DataConnection.Count, "ItemsSource was not set from the original DataContext");
                dataGrid.DataContext = stringsContainer2;
            });
            this.EnqueueYieldThread();

            this.EnqueueCallback(delegate
            {
                Assert.AreEqual(stringsContainer2.Strings, dataGrid.ItemsSource, "ItemsSource did not change along with the DataContext");
                Assert.AreEqual(5, dataGrid.DataConnection.Count, "ItemsSource did not change along with the DataContext");
            });
            this.EnqueueTestComplete();
        }
Exemple #3
0
 protected BaseMarketingController()
 {
     Container = new StringsContainer();
 }