本文整理汇总了C#中System.Windows.Controls.ListBox.SetBinding方法的典型用法代码示例。如果您正苦于以下问题:C# ListBox.SetBinding方法的具体用法?C# ListBox.SetBinding怎么用?C# ListBox.SetBinding使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Controls.ListBox
的用法示例。
在下文中一共展示了ListBox.SetBinding方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ListColorsEvenElegantlier
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;
}
示例2: SelectionChangedHandler
internal SelectionChangedHandler(ListBox owner)
{
Binding = new Binding("SelectedItems");
Binding.Source = owner;
owner.SetBinding(ListBoxExtentions.BindableSelectedItemsProperty, Binding);
owner.SelectionChanged += new SelectionChangedEventHandler(Owner_SelectionChanged);
}
示例3: UIBoundToCustomerWithItemsControl
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: BindToEnumerable_CVS
public void BindToEnumerable_CVS ()
{
var target = new ListBox ();
target.SetBinding (ListBox.ItemsSourceProperty, new Binding {
Source = Source
});
Assert.AreSame (Source.View, target.ItemsSource, "#1");
}
示例5: ListColorsEvenElegantlier
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;
}
示例6: ListNamedBrushes
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;
}
示例7: ListNamedBrushes
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;
}
示例8: ComboBox
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);
}
示例9: AddRow
/// <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);
}
示例10: InitializeBoundControls
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);
}
示例11: CreateEnumControl
/// <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;
}
}
示例12: Bind_Collection_CurrentItem
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);
}