Пример #1
0
        protected override FrameworkElement CreateDynamicEditingElement(Entity curEntity)
        {
            var value = this.PropertyValue;

            //支持两种属性类型:DateRange,String,所以这里使用这个变量进行分辨
            var useNumberRangeType = this.Meta.PropertyMeta.Runtime.PropertyType == typeof(NumberRange);

            var range = useNumberRangeType ?
                new NumberRange(value as NumberRange) :
                NumberRange.Parse(value != null ? value as string : string.Empty);

            var rangeControl = new NumberRangePropertyEditorControl(range);
            rangeControl.Confirm += (ss, ee) =>
            {
                if (useNumberRangeType)
                {
                    var raw = value as NumberRange;
                    raw.BeginValue = ee.Range.BeginValue;
                    raw.EndValue = ee.Range.EndValue;
                }
                else
                {
                    this.PropertyValue = ee.Range.ToString();
                }
            };

            rangeControl.KeyDown += (oo, ee) =>
            {
                if (ee.Key == Key.Enter)
                {
                    FocusNavigationDirection focusDirection = FocusNavigationDirection.Next;
                    TraversalRequest request = new TraversalRequest(focusDirection);
                    rangeControl.MoveFocus(request);
                }
            };

            this.AddReadOnlyComponent(rangeControl);

            this.SetAutomationElement(rangeControl);

            return rangeControl;
        }