本文整理汇总了C#中System.Windows.Controls.ComboBox.GetBindingExpression方法的典型用法代码示例。如果您正苦于以下问题:C# ComboBox.GetBindingExpression方法的具体用法?C# ComboBox.GetBindingExpression怎么用?C# ComboBox.GetBindingExpression使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Controls.ComboBox
的用法示例。
在下文中一共展示了ComboBox.GetBindingExpression方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Initialize
private void Initialize(CB comboBox, bool useEagerSelection)
{
// Add to visual tree to enable ElementName binding
comboBox.Tag = this._bindingListener;
this._useEagerSelection = useEagerSelection;
BindingExpression be = comboBox.GetBindingExpression(ItemsControl.ItemsSourceProperty);
if (be != null)
{
BindingOperations.SetBinding(this._bindingListener, BindingListener.ItemsSourceProperty, be.ParentBinding);
BindingOperations.SetBinding(comboBox, ItemsControl.ItemsSourceProperty, new Binding("Items") { Source = this });
}
be = comboBox.GetBindingExpression(Selector.SelectedItemProperty);
if (be != null)
{
BindingOperations.SetBinding(this._bindingListener, BindingListener.SelectedItemProperty, be.ParentBinding);
BindingOperations.SetBinding(comboBox, Selector.SelectedItemProperty, new Binding("SelectedItem") { Source = this, Mode = BindingMode.TwoWay });
}
be = comboBox.GetBindingExpression(Selector.SelectedValueProperty);
if (be != null)
{
// We'll always bind the ComboBox to SelectedItem, but we'll map it to the existing SelectedValue binding
this._selectedValueMode = true;
BindingOperations.SetBinding(this._bindingListener, BindingListener.SelectedValueProperty, be.ParentBinding);
comboBox.ClearValue(Selector.SelectedValueProperty);
// Bind SelectedValuePath
be = comboBox.GetBindingExpression(Selector.SelectedValuePathProperty);
if (be != null)
{
BindingOperations.SetBinding(this._bindingListener, BindingListener.SelectedValuePathProperty, be.ParentBinding);
comboBox.ClearValue(Selector.SelectedValuePathProperty);
}
else
{
this._bindingListener.SelectedValuePath = comboBox.SelectedValuePath;
comboBox.SelectedValuePath = null;
}
// Bind DisplayMemberPath
be = comboBox.GetBindingExpression(Selector.DisplayMemberPathProperty);
if (be != null)
{
BindingOperations.SetBinding(this._bindingListener, BindingListener.DisplayMemberPathProperty, be.ParentBinding);
}
else
{
this._bindingListener.DisplayMemberPath = comboBox.DisplayMemberPath;
}
BindingOperations.SetBinding(comboBox, Selector.DisplayMemberPathProperty, new Binding("DisplayMemberPath") { Source = this });
// Check selection mode and path properties
if (this._useEagerSelection && (this._bindingListener.DisplayMemberPath != this._bindingListener.SelectedValuePath))
{
throw new InvalidOperationException("Cannot use eager selection when the DisplayMemberPath and the SelectedValuePath differ. Try using basic ComboBoxMode.Async selection instead.");
}
BindingOperations.SetBinding(comboBox, Selector.SelectedItemProperty, new Binding("SelectedItem") { Source = this, Mode = BindingMode.TwoWay });
}
}
示例2: createSizeType
private UIElement createSizeType(int marginTop, string propName)
{
ComboBox comboBox = new ComboBox();
comboBox.Margin = new Thickness(0, marginTop, 0, 0);
comboBox.Height = 28;
comboBox.HorizontalAlignment = HorizontalAlignment.Left;
comboBox.Name = propName + "textBox";
comboBox.VerticalAlignment = VerticalAlignment.Top;
comboBox.Width = 120;
comboBox.Items.Insert(0, "pix");
comboBox.Items.Insert(1, "per");
Binding binding = new Binding(propName);
binding.Source = WhatsappProperties.Instance;
binding.UpdateSourceTrigger = UpdateSourceTrigger.Explicit;
comboBox.SetBinding(ComboBox.SelectedValueProperty, binding);
BindingExpression be = comboBox.GetBindingExpression(ComboBox.SelectedValueProperty);
BindingExpressions.Add(be);
return comboBox;
}