public void ControlWithExistingBindingOnItemsSourceWithNullValueThrows()
        {
            var control = new ItemsControl();
            Binding binding = new Binding("Enumerable");
            binding.Source = new SimpleModel() { Enumerable = null };
            control.SetBinding(ItemsControl.ItemsSourceProperty, binding);

            IRegionAdapter adapter = new TestableItemsControlRegionAdapter();

            try
            {
                var region = (MockPresentationRegion)adapter.Initialize(control, "Region1");
                Assert.Fail();
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(ex, typeof(InvalidOperationException));
                StringAssert.Contains(ex.Message, "ItemsControl's ItemsSource property is not empty.");
            }
        }
        /// <summary>
        /// Creates a sequence of checkboxes.
        /// </summary>
        /// <param name="property">The property.</param>
        /// <returns>
        /// A FrameworkElement.
        /// </returns>
        protected virtual FrameworkElement CreateCheckableItems(PropertyItem property)
        {
            var lb = new ItemsControl();
            var rectangleFactory = new FrameworkElementFactory(typeof(CheckBox));
            rectangleFactory.SetBinding(ToggleButton.IsCheckedProperty, new Binding(property.CheckableItemsIsCheckedPropertyName));
            rectangleFactory.SetBinding(ContentControl.ContentProperty, new Binding(property.CheckableItemsContentPropertyName));

            lb.ItemTemplate = new DataTemplate { VisualTree = rectangleFactory };
            lb.SetBinding(ItemsControl.ItemsSourceProperty, property.CreateBinding());
            lb.Margin = new Thickness(0, 6, 0, 6);

            return lb;
        }
        public PluginBase()
        {
            // Any inputs the plugin may have
            Inputs = new ObservableDictionary<string, InputSignalViewModel>();

            // Create style resources with the correct 5px margin
            Style ButtonStyle = new Style(typeof(Button), (Style)FindResource(typeof(Button)));
            ButtonStyle.Setters.Add(new Setter(Button.MarginProperty, new Thickness(5)));
            // StackPanel that holds our signal sources
            OutputsStackPanel = new StackPanel();

            // "Signal Source Mapping" title textblock
            TextBlock signalSourceViewTitle = new TextBlock();
            signalSourceViewTitle.Text = "Signal Output Mapping";
            signalSourceViewTitle.Style = (Style)Application.Current.Resources["Title"];
            OutputsStackPanel.Children.Add(signalSourceViewTitle);

            // ObservableDictionary to hold all of the signal sources that our plugin might have
            Outputs = new ObservableDictionary<string, OutputSignalViewModel>();

            // GUI element to display all of the items properly using a SignalSourceView
            ItemsControl SignalSourceControl = new ItemsControl();
            DataTemplate signalDataTemplate = CreateTemplate(typeof(OutputSignalViewModel), typeof(SignalSourceView));
            var key = signalDataTemplate.DataTemplateKey;
            if(Application.Current.Resources[key] == null)
                Application.Current.Resources.Add(key, signalDataTemplate);
            SignalSourceControl.SetBinding(ItemsControl.ItemsSourceProperty, "Outputs.Values");
            OutputsStackPanel.Children.Add(SignalSourceControl);

            // Set the plugin datacontext to itself -- we assume we're not doing separate view models.
            this.DataContext = this;
            MainArea = new StackPanel();
            SetCurrentValue(PluginContentProperty, new StackPanel());

            // [Plugin Name] Configuration title textblock
            TextBlock title = new TextBlock();
            title.SetBinding(TextBlock.TextProperty, "DisplayTitle");
            title.Style = (Style)Application.Current.Resources["Title"];

            ModernButton infoButton = new ModernButton();
            var streamGeometry = StreamGeometry.Parse("F1 M 38,19C 48.4934,19 57,27.5066 57,38C 57,48.4934 48.4934,57 38,57C 27.5066,57 19,48.4934 19,38C 19,27.5066 27.5066,19 38,19 Z M 33.25,33.25L 33.25,36.4167L 36.4166,36.4167L 36.4166,47.5L 33.25,47.5L 33.25,50.6667L 44.3333,50.6667L 44.3333,47.5L 41.1666,47.5L 41.1666,36.4167L 41.1666,33.25L 33.25,33.25 Z M 38.7917,25.3333C 37.48,25.3333 36.4167,26.3967 36.4167,27.7083C 36.4167,29.02 37.48,30.0833 38.7917,30.0833C 40.1033,30.0833 41.1667,29.02 41.1667,27.7083C 41.1667,26.3967 40.1033,25.3333 38.7917,25.3333 Z ");
            infoButton.IconData = streamGeometry;
            infoButton.Command = ToggleInfoCommand;

            InfoTextBlock = new TextBlock();
            //InfoTextBlock.SetBinding(TextBox.TextProperty, "InfoString");
            //            InfoTextBlock.Text = "Info...";
            InfoTextBlock.Visibility = Visibility.Collapsed;
            InfoTextBlock.TextWrapping = TextWrapping.Wrap;
            Binding infoBinding = new Binding();
            infoBinding.Path = new PropertyPath("InfoString");
            BindingOperations.SetBinding(InfoTextBlock, TextBlock.TextProperty, infoBinding);

            UniformGrid grid1 = new UniformGrid();
            grid1.Columns = 2;
            grid1.Children.Add(title);
            grid1.Children.Add(infoButton);

            // Instance name GUI stuff
            UniformGrid grid2 = new UniformGrid();
            TextBlock InstanceNameLabel = new TextBlock();
            InstanceNameLabel.Text = "Instance Name";
            TextBox InstanceNameBox = new TextBox();
            Binding binding = new Binding();
            binding.Path = new PropertyPath("InstanceName");
            InstanceNameBox.SetBinding(TextBox.TextProperty, binding);
            grid2.Columns = 2;
            grid2.Children.Add(InstanceNameLabel);
            grid2.Children.Add(InstanceNameBox);
            MainArea.Children.Add(grid1);
            MainArea.Children.Add(InfoTextBlock);
            MainArea.Children.Add(grid2);

            this.Initialized += PluginBase_Initialized;
        }