示例#1
0
        protected override FrameworkElement CreateEditingElement()
        {
            this._cb      = new ComboBox();
            this._cb.Name = this.Meta.Name;
            this._cb.SelectedValuePath = "EnumValue";
            this._cb.DisplayMemberPath = "TranslatedLabel";

            this.ResetBinding(this._cb);

            //cb.Items.Clear();
            var propertyType = this.Meta.PropertyMeta.Runtime.PropertyType;

            foreach (var item in EnumViewModel.GetByEnumType(propertyType))
            {
                this._cb.Items.Add(item);
            }
            if (TypeHelper.IsNullable(propertyType))
            {
                //这种组合下,不能随意录入值、可以选择文本、按上下键选择项。缺点是不能通过输入搜索项。
                this._cb.IsEditable      = true;
                this._cb.IsReadOnly      = true;
                this._cb.PreviewKeyDown += On_cb_PreviewKeyDown;
            }

            this.AddReadOnlyComponent(this._cb, ComboBox.IsEnabledProperty, false);

            this.SetAutomationElement(this._cb);

            this._cb.SelectionChanged   += On_cb_SelectionChanged;
            this._cb.DropDownOpened     += On_cb_DropDownOpened;
            this._cb.DataContextChanged += On_cb_DataContextChanged;

            return(this._cb);
        }
示例#2
0
        public EnumBoxConfig(Type enumType)
        {
            this.queryMode    = "local";
            this.displayField = "text";
            this.valueField   = "text";
            var models = EnumViewModel.GetByEnumType(enumType);

            this.store = new ArrayStoreConfig
            {
                fields = new string[] { "text", "value" },
                data   = models.Select(vm => new EnumModel
                {
                    text  = vm.Label,
                    value = (int)(object)vm.EnumValue
                }).ToArray()
            };
        }