internal SelectionChangedHandler(ListBox owner)
 {
     Binding = new Binding("SelectedItems");
     Binding.Source = owner;
     owner.SetBinding(ListBoxExtentions.BindableSelectedItemsProperty, Binding);
     owner.SelectionChanged += new SelectionChangedEventHandler(Owner_SelectionChanged);
 }
        public ListColorsEvenElegantlier()
        {
            Title = "List Colors Even Elegantlier";

            DataTemplate template = new DataTemplate(typeof(NamedBrush));
            FrameworkElementFactory factoryStack = new FrameworkElementFactory(typeof(StackPanel));
            factoryStack.SetValue(StackPanel.OrientationProperty, Orientation.Horizontal);
            template.VisualTree = factoryStack;

            FrameworkElementFactory factoryRectangle = new FrameworkElementFactory(typeof(Rectangle));
            factoryRectangle.SetValue(Rectangle.WidthProperty, 16.0);
            factoryRectangle.SetValue(Rectangle.HeightProperty, 16.0);
            factoryRectangle.SetValue(Rectangle.MarginProperty, new Thickness(2));
            factoryRectangle.SetValue(Rectangle.StrokeProperty, SystemColors.WindowTextBrush);
            factoryRectangle.SetBinding(Rectangle.FillProperty, new Binding("Brush"));
            factoryStack.AppendChild(factoryRectangle);

            FrameworkElementFactory factoryTextBlock = new FrameworkElementFactory(typeof(TextBlock));
            factoryTextBlock.SetValue(TextBlock.VerticalAlignmentProperty, VerticalAlignment.Center);
            factoryTextBlock.SetValue(TextBlock.TextProperty, new Binding("Name"));
            factoryStack.AppendChild(factoryTextBlock);

            ListBox lstbox = new ListBox();
            lstbox.Width = 150;
            lstbox.Height = 150;
            Content = lstbox;

            lstbox.ItemTemplate = template;
            lstbox.ItemsSource = NamedBrush.All;

            lstbox.SelectedValuePath = "Brush";
            lstbox.SetBinding(ListBox.SelectedValueProperty, "Background");
            lstbox.DataContext = this;
        }
        public UIBoundToCustomerWithItemsControl()
        {
            var stack = new StackPanel();
            Content = stack;

            var textBlock = new TextBlock();
            textBlock.SetBinding(TextBlock.TextProperty, new Binding("FirstName"));
            stack.Children.Add(textBlock);

            textBlock = new TextBlock();
            textBlock.SetBinding(TextBlock.TextProperty, new Binding("LastName"));
            stack.Children.Add(textBlock);

            var addressStack = new StackPanel();
            stack.Children.Add(addressStack);

            textBlock = new TextBlock();
            textBlock.SetBinding(TextBlock.TextProperty, new Binding("MailingAddress.Street")); //misspelling
            addressStack.Children.Add(textBlock);

            textBlock = new TextBlock();
            textBlock.SetBinding(TextBlock.TextProperty, new Binding("MailingAddress.City"));
            addressStack.Children.Add(textBlock);

            textBlock = new TextBlock();
            textBlock.SetBinding(TextBlock.TextProperty, new Binding("BllingAddress.Street2")); //misspelling
            addressStack.Children.Add(textBlock);

            var listBox = new ListBox {ItemTemplate = CreateItemTemplate()};
            listBox.SetBinding(ListBox.ItemsSourceProperty, new Binding("Orders"));
            stack.Children.Add(listBox);
        }
示例#4
0
		public void BindToEnumerable_CVS ()
		{
			var target = new ListBox ();
			target.SetBinding (ListBox.ItemsSourceProperty, new Binding {
				Source = Source
			});
			Assert.AreSame (Source.View, target.ItemsSource, "#1");
		}
示例#5
0
 internal SelectionChangedHandler(System.Windows.Controls.ListBox owner)
 {
     _binding = new Binding("SelectedItems")
     {
         Source = owner
     };
     owner.SetBinding(ItemsElementBehavior.BindableSelectedItemsProperty, _binding);
     owner.SelectionChanged += Owner_SelectionChanged;
 }
        public ListColorsEvenElegantlier()
        {
            Title = "List Colors Even Elegantlier";

            // Create a DataTemplate for the items.
            DataTemplate template = new DataTemplate(typeof(NamedBrush));

            // Create a FrameworkElementFactory based on StackPanel.
            FrameworkElementFactory factoryStack =
                                new FrameworkElementFactory(typeof(StackPanel));
            factoryStack.SetValue(StackPanel.OrientationProperty,
                                                Orientation.Horizontal);

            // Make that the root of the DataTemplate visual tree.
            template.VisualTree = factoryStack;

            // Create a FrameworkElementFactory based on Rectangle.
            FrameworkElementFactory factoryRectangle =
                                new FrameworkElementFactory(typeof(Rectangle));
            factoryRectangle.SetValue(Rectangle.WidthProperty, 16.0);
            factoryRectangle.SetValue(Rectangle.HeightProperty, 16.0);
            factoryRectangle.SetValue(Rectangle.MarginProperty, new Thickness(2));
            factoryRectangle.SetValue(Rectangle.StrokeProperty,
                                            SystemColors.WindowTextBrush);
            factoryRectangle.SetBinding(Rectangle.FillProperty,
                                            new Binding("Brush"));
            // Add it to the StackPanel.
            factoryStack.AppendChild(factoryRectangle);

            // Create a FrameworkElementFactory based on TextBlock.
            FrameworkElementFactory factoryTextBlock =
                                new FrameworkElementFactory(typeof(TextBlock));
            factoryTextBlock.SetValue(TextBlock.VerticalAlignmentProperty,
                                            VerticalAlignment.Center);
            factoryTextBlock.SetValue(TextBlock.TextProperty,
                                            new Binding("Name"));
            // Add it to the StackPanel.
            factoryStack.AppendChild(factoryTextBlock);

            // Create ListBox as content of window.
            ListBox lstbox = new ListBox();
            lstbox.Width = 150;
            lstbox.Height = 150;
            Content = lstbox;

            // Set the ItemTemplate property to the template created above.
            lstbox.ItemTemplate = template;

            // Set the ItemsSource to the array of NamedBrush objects.
            lstbox.ItemsSource = NamedBrush.All;

            // Bind the SelectedValue to window Background.
            lstbox.SelectedValuePath = "Brush";
            lstbox.SetBinding(ListBox.SelectedValueProperty, "Background");
            lstbox.DataContext = this;
        }
示例#7
0
        public ListNamedBrushes()
        {
            Title = "List Named Brushes";

            ListBox lstbox = new ListBox();
            lstbox.Width = 150;
            lstbox.Height = 150;
            Content = lstbox;

            lstbox.ItemsSource = NamedBrush.All;
            lstbox.DisplayMemberPath = "Name";
            lstbox.SelectedValuePath = "Brush";

            lstbox.SetBinding(ListBox.SelectedValueProperty, "Background");
            lstbox.DataContext = this;
        }
        public ListNamedBrushes()
        {
            Title = "List Named Brushes";

            ListBox lstbox = new ListBox();
            lstbox.Width = 150;
            lstbox.Height = 150;
            Content = lstbox;

            //�׸�� ������Ƽ �н��� ����...
            lstbox.ItemsSource = NamedBrush.All;
            lstbox.DisplayMemberPath = "Name";
            lstbox.SelectedValuePath = "Brush";             //<---����Ʈ�ڽ��� NamedBrush ��ü�� �������� brush�� ����...

            //selectedValue�� ������ ���� ���ε�..
            lstbox.SetBinding(ListBox.SelectedValueProperty, "Background");
            lstbox.DataContext = this;
        }
        public ListNamedBrushes()
        {
            Title = "List Named Brushes";

            // Create ListBox as content of window.
            ListBox lstbox = new ListBox();
            lstbox.Width = 150;
            lstbox.Height = 150;
            Content = lstbox;

            // Set the items and the property paths.
            lstbox.ItemsSource = NamedBrush.All;
            lstbox.DisplayMemberPath = "Name";
            lstbox.SelectedValuePath = "Brush";

            // Bind the SelectedValue to window Background.
            lstbox.SetBinding(ListBox.SelectedValueProperty, "Background");
            lstbox.DataContext = this;
        }
示例#10
0
        public ComboBox( )
        {
            this.Background = Brushes.Red;

            this.Padding = new Thickness();
            this.Margin  = new Thickness();

            window  = new Window(this);
            cmdItem = new Button();
            lbItems = new ListBox();

            var itemsBinding = new Binding();

            itemsBinding.Mode   = BindingMode.OneWay;
            itemsBinding.Source = this;
            itemsBinding.Path   = new PropertyPath("Items");

            lbItems.Margin             = new Thickness(2);
            lbItems.BorderThickness    = new Thickness(0);
            lbItems.ItemContainerStyle = (Style)this.FindResource("ComboBoxItemStyle");
            lbItems.SetBinding(ListBox.ItemsProperty, itemsBinding);
            lbItems.SelectionChanged += (s, e) => {
                window.DialogResult = this.SelectedItem != null;
                window.Close();
                this.IsDropDownOpen = false;
            };

            window.Content = lbItems;

            var selectedItemBinding = new Binding("SelectedItem");

            selectedItemBinding.Mode   = BindingMode.TwoWay;
            selectedItemBinding.Source = lbItems;

            cmdItem.SetBinding(
                Button.ContentProperty,
                selectedItemBinding);

            this.SetBinding(
                ListBox.SelectedItemProperty,
                selectedItemBinding);
        }
示例#11
0
        public ComboBox ( ) {
			this.Background = Brushes.Red;

			this.Padding = new Thickness ();
			this.Margin = new Thickness ();

			window = new Window(this);
			cmdItem = new Button ();
			lbItems = new ListBox ();

			var itemsBinding = new Binding ();
			itemsBinding.Mode = BindingMode.OneWay;
			itemsBinding.Source = this;
			itemsBinding.Path = new PropertyPath ("Items");

			lbItems.Margin = new Thickness (2);
			lbItems.BorderThickness = new Thickness (0);
			lbItems.ItemContainerStyle = (Style)this.FindResource ("ComboBoxItemStyle");
			lbItems.SetBinding (ListBox.ItemsProperty, itemsBinding);
			lbItems.SelectionChanged += (s,e) => {
				window.DialogResult = this.SelectedItem != null;
				window.Close ();
				this.IsDropDownOpen = false;
			};
				
			window.Content = lbItems;

			var selectedItemBinding = new Binding ("SelectedItem");
			selectedItemBinding.Mode = BindingMode.TwoWay;
			selectedItemBinding.Source = lbItems;

			cmdItem.SetBinding (
				Button.ContentProperty, 
				selectedItemBinding);

			this.SetBinding (
				ListBox.SelectedItemProperty, 
				selectedItemBinding);
        }
示例#12
0
        /// <summary>
        /// Adds a row and associated bindings for each UIElement to the grid.
        /// </summary>
        /// <param name="rowNum"></param>
        private void AddRow(int rowNum)
        {
            ResearchFactor rf = new ResearchFactor();

            //Create a new research factor if there isn't one already, otherwise select that research factor
            if(_efViewModel.ResearchFactors.Count <= rowNum)
                _efViewModel.ResearchFactors.Add(rf);
            else
                rf = _efViewModel.ResearchFactors[rowNum];

            //box for label
            var tb = new TextBox
            {
                Height = 20,
                Width = 170,
                Name = "factorName",

            };

            Binding binding = new Binding("Name") { Source = rf };
            binding.Mode = BindingMode.TwoWay;
            tb.SetBinding(TextBox.TextProperty, binding);

            Grid.SetRow(tb, rowNum + 1);
            Grid.SetColumn(tb, 0);

            //Button for creating levels
            var createlevels = new Button
            {
                Content = "Create levels",
                Width = 80,
                Height = 20,
                HorizontalAlignment = HorizontalAlignment.Left
            };

            createlevels.Click += createlevels_OnClick;
            StackPanel sp = new StackPanel();
            sp.Margin = new Thickness(10);
            Grid.SetRow(sp, rowNum + 1);
            Grid.SetColumn(sp, 1);

            //Listbox for the labels to be displayed in
            var labelList = new ListBox { MinHeight = 45, MaxHeight = 45 };

            binding = new Binding("Labels") { Source = rf };
            binding.Mode = BindingMode.TwoWay;
            labelList.SetBinding(ListBox.ItemsSourceProperty, binding);

            sp.Children.Add(labelList);
            sp.Children.Add(createlevels);

            //checkbox for isRandomized
            var checkbox = new CheckBox
            {
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment = VerticalAlignment.Center
            };

            binding = new Binding("IsRandomized") { Source = rf };
            binding.Mode = BindingMode.TwoWay;
            checkbox.SetBinding(CheckBox.IsCheckedProperty, binding);

            Grid.SetRow(checkbox, rowNum + 1);
            Grid.SetColumn(checkbox, 2);

            //combobox for within/between subjects selection
            var cb = new ComboBox
            {
                Width = 150,
                Height = 20
            };

            string ComboBoxTrueValue = _efViewModel.DesignTypes[0]; //"Within Subjects Factor";
            string ComboBoxFalseValue = _efViewModel.DesignTypes[1]; //"Between Subjects Factor";

            Binding binding2 = new Binding("DesignTypes") { Source = _efViewModel };
            binding2.Mode = BindingMode.TwoWay;
            cb.SetBinding(ComboBox.ItemsSourceProperty, binding2);

            binding = new Binding("IsWithinSubjects") { Source = rf, Converter = new StringToBoolConverter { TrueValue = ComboBoxTrueValue, FalseValue = ComboBoxFalseValue } };
            binding.Mode = BindingMode.TwoWay;
            cb.SetBinding(ComboBox.SelectedValueProperty, binding);

            Grid.SetRow(cb, rowNum + 1); // I guess this means that "whatever grid you put me in, I'll be in this row and this column.
            Grid.SetColumn(cb, 3);

            factorGrid.Children.Add(tb);
            factorGrid.Children.Add(sp);
            factorGrid.Children.Add(checkbox);
            factorGrid.Children.Add(cb);
        }
        private void InitializeBoundControls()
        {
            var addItemToCollectionButton = new Button { Content = "+", Margin = new Thickness(2, 0, 2, 0) };
            var modItemInCollectionButton = new Button { Content = "~", Margin = new Thickness(2, 0, 2, 0) };
            var visualItemCollection = new ListBox();

            var factory = new FrameworkElementFactory(typeof(VirtualizingStackPanel));
            factory.SetValue(VirtualizingStackPanel.OrientationProperty, Orientation.Horizontal);

            visualItemCollection.ItemsPanel = new ItemsPanelTemplate(factory);

            this.AddAutoHeightRow();
            this.AddChild(addItemToCollectionButton, this.LastRowIndex(), 0);
            this.AddChild(modItemInCollectionButton, this.LastRowIndex(), 1);
            this.AddChild(visualItemCollection, this.LastRowIndex(), 2);

            addItemToCollectionButton.Click += addItemToCollectionButton_Click;
            modItemInCollectionButton.Click += modItemInCollectionButton_Click;

            var binding = new Binding
            {
                Source = _itemCollectionDatabag,
                Path = new PropertyPath("TextBlockList")
            };

            visualItemCollection.SetBinding(ListBox.ItemsSourceProperty, binding);
        }
        /// <summary>
        /// Creates the select control.
        /// </summary>
        /// <param name="property">The property.</param>
        /// <param name="options">The options.</param>
        /// <returns>
        /// The control.
        /// </returns>
        protected virtual FrameworkElement CreateEnumControl(
            PropertyItem property, PropertyControlFactoryOptions options)
        {
            var enumType = TypeHelper.GetEnumType(property.Descriptor.PropertyType);
            var values = Enum.GetValues(enumType);
            var style = property.SelectorStyle;
            if (style == DataAnnotations.SelectorStyle.Auto)
            {
                style = values.Length > options.EnumAsRadioButtonsLimit
                            ? DataAnnotations.SelectorStyle.ComboBox
                            : DataAnnotations.SelectorStyle.RadioButtons;
            }

            switch (style)
            {
                case DataAnnotations.SelectorStyle.RadioButtons:
                    {
                        var c = new RadioButtonList { EnumType = property.Descriptor.PropertyType };
                        c.SetBinding(RadioButtonList.ValueProperty, property.CreateBinding());
                        return c;
                    }

                case DataAnnotations.SelectorStyle.ComboBox:
                    {
                        var c = new ComboBox { ItemsSource = Enum.GetValues(enumType) };
                        c.SetBinding(Selector.SelectedValueProperty, property.CreateBinding());
                        return c;
                    }

                case DataAnnotations.SelectorStyle.ListBox:
                    {
                        var c = new ListBox { ItemsSource = Enum.GetValues(enumType) };
                        c.SetBinding(Selector.SelectedValueProperty, property.CreateBinding());
                        return c;
                    }

                default:
                    return null;
            }
        }
示例#15
0
        static void Bind_Collection_CurrentItem()
        {
            var taro = new Person1 { Id = 123, Name = "Taro" };
            var jiro = new Person1 { Id = 234, Name = "Jiro" };
            var people = new[] { taro, jiro };

            var grid = new Grid { DataContext = people };
            var listBox = new ListBox { IsSynchronizedWithCurrentItem = true };
            grid.Children.Add(listBox);
            var textBlock = new TextBlock { Text = "Default" };
            grid.Children.Add(textBlock);

            textBlock.SetBinding(FrameworkElement.DataContextProperty, new Binding("/"));
            textBlock.SetBinding(TextBlock.TextProperty, new Binding("Name"));
            Console.WriteLine((listBox.SelectedValue as Person1)?.Name ?? "null");
            Console.WriteLine(textBlock.Text);

            // MEMO: In case that IsSynchronizedWithCurrentItem is false, SelectedValue is null.
            listBox.SetBinding(ItemsControl.ItemsSourceProperty, new Binding());
            Console.WriteLine((listBox.SelectedValue as Person1)?.Name ?? "null");
            Console.WriteLine(textBlock.Text);

            listBox.SelectedValue = jiro;
            Console.WriteLine((listBox.SelectedValue as Person1)?.Name ?? "null");
            Console.WriteLine(textBlock.Text);
        }