当前位置: 首页>>代码示例>>C#>>正文


C# ComboBox.GetBindingExpression方法代码示例

本文整理汇总了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 });
                }
            }
开发者ID:shenoyroopesh,项目名称:Gama,代码行数:64,代码来源:ComboBox.cs

示例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;
        }
开发者ID:Karthikeyan-kkk,项目名称:whatsapp-shower,代码行数:21,代码来源:Settings.xaml.cs


注:本文中的System.Windows.Controls.ComboBox.GetBindingExpression方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。