/// <summary> /// 生成GridTreeView列对象 /// </summary> /// <param name="meta"></param> /// <returns></returns> public TreeColumn Create(WPFEntityPropertyViewMeta meta) { //根据editorName生成对应的Column var treeColumn = this.CreateInstance(meta.GetEditorNameOrDefault()) ?? new CommonTreeColumn(); treeColumn.Meta = meta; var editor = this._propertyEditorFactory.Create(meta, true); treeColumn.Editor = editor; //使用 PropertyEditor 来生成 Binding 的原因是: //如果是下拉框、则不能直接使用默认的绑定方案。 treeColumn.Binding = CreateBindingByEditor(editor); treeColumn.HeaderLabel = (meta.Label ?? meta.Name).Translate(); treeColumn.PropertyName = meta.Name; treeColumn.SortingProperty = meta.DisplayPath(); treeColumn.DisplayTextBlockStyle = TypeHelper.IsNumber(TypeHelper.IgnoreNullable(meta.PropertyMeta.Runtime.PropertyType)) ? RafyResources.TreeColumn_TextBlock_Number : RafyResources.TreeColumn_TextBlock; //宽度 if (meta.GridWidth.HasValue) { treeColumn.Width = meta.GridWidth.Value; } return(treeColumn); }
/// <summary> /// 为某个属性生成指定类型的属性编辑器 /// </summary> /// <param name="editorType">指定使用这种编辑器类型</param> /// <param name="propertyInfo"></param> /// <returns></returns> public PropertyEditor Create(Type editorType, WPFEntityPropertyViewMeta propertyInfo, bool forList) { var result = Activator.CreateInstance(editorType, true) as PropertyEditor; this.InitPropertyEditor(result, propertyInfo, forList); return(result); }
/// <summary> /// 根据属性元数据中指定的 EditorName 生成属性编辑器 /// </summary> /// <param name="property"></param> /// <param name="forList"></param> /// <returns></returns> public PropertyEditor Create(WPFEntityPropertyViewMeta property, bool forList) { var result = this.CreateInstance(property.GetEditorNameOrDefault(), true) ?? this.CreateInstance(WPFEditorNames.String, true); this.InitPropertyEditor(result, property, forList); return(result); }
protected void InitPropertyEditor(PropertyEditor result, WPFEntityPropertyViewMeta propertyInfo, bool forList) { result._context.IsForList = forList; result.Initialize(propertyInfo); result.EnsureControlsCreated(); this.OnInstanceCreated(result); }
/// <summary> /// 在所有控件生成后,为他们的可见性进行属性绑定 /// </summary> private void BindVisibility(WPFEntityPropertyViewMeta meta) { var visibilityIndicator = meta.VisibilityIndicator; if (visibilityIndicator.IsDynamic) { Binding visibleBinding = new Binding(visibilityIndicator.Property.Name); visibleBinding.Mode = BindingMode.OneWay; visibleBinding.Converter = new BooleanToVisibilityConverter(); this.SetBinding(UIElement.VisibilityProperty, visibleBinding); } }
private void SetLayoutValues(DetailLogicalView detailView, WPFEntityPropertyViewMeta property) { if (property.DetailAsHorizontal != null) { var direction = property.DetailAsHorizontal.Value ? Orientation.Horizontal : Orientation.Vertical; this.SetIfNonLocal(OrientationProperty, direction); } if (property.DetailColumnsSpan != null) { this.SetIfNonLocal(Grid.ColumnSpanProperty, property.DetailColumnsSpan.Value); } var labelSize = property.DetailLabelSize ?? detailView.Meta.DetailLabelSize; if (labelSize != null) { if (this.Orientation == Orientation.Horizontal) { this.SetIfNonLocal(LabelWidthProperty, labelSize.Value); } else { this.SetIfNonLocal(LabelHeightProperty, labelSize.Value); } } if (property.DetailContentWidth != null) { if (!this.IsLocalValue(ContentWidthProperty)) { var value = property.DetailContentWidth.Value; //0-1 之间表示相对值,否则表示绝对值。 if (value > 0 && value < 1) { value = value / (1 - value); this.ContentWidth = new GridLength(value, GridUnitType.Star); } else { this.ContentWidth = new GridLength(value); } } } if (property.DetailHeight != null) { this.SetIfNonLocal(HeightProperty, property.DetailHeight.Value); } }
private static string FormatPropertyLabel(WPFEntityPropertyViewMeta property) { //var label = property.Label; //if (!string.IsNullOrWhiteSpace(label)) //{ // //尝试把一些已知的字符替换掉。 // label = Regex.Replace(label, @"[\(\)(){}“”""\\/-]", string.Empty); // if (label.Length > 0) // { // return property.Name + "__" + label; // } //} return(property.Name); }
/// <summary> /// 检测某个实体对象的某个实体属性是否可以只读。 /// </summary> /// <param name="entity"></param> /// <param name="property"></param> /// <returns></returns> internal static bool CheckIsReadOnly(Entity entity, WPFEntityPropertyViewMeta property) { //类指明为只读 var indicator = property.ReadonlyIndicator; if (indicator.Status == ReadOnlyStatus.ReadOnly || property.Owner.NotAllowEdit) { return(true); } //检测动态属性 if (indicator.Status == ReadOnlyStatus.Dynamic && entity != null) { return((bool)entity.GetProperty(indicator.Property)); } return(false); }
protected virtual string ReadProperty(WPFEntityPropertyViewMeta property) { var data = string.Empty; try { if (property.IsReference) { var displayPath = property.DisplayPath(); var value = ObjectHelper.GetPropertyValue(this._currentRow, displayPath); if (value != null) { data = value.ToString(); } } else { var mp = property.PropertyMeta.ManagedProperty; if (mp != null) { var value = this._currentRow.GetProperty(mp); if (value != null) { if (TypeHelper.IsEnumNullable(mp.PropertyType)) { data = EnumViewModel.EnumToLabel((Enum)value).Translate(); } else { data = value.ToString(); } } } } } catch { //尽量尝试读取值,读取出错,则忽略错误。 } return(data); }
internal static void SetNeedSummary(WPFEntityPropertyViewMeta meta, bool?value) { meta.SetExtendedProperty(PropertyMetaNeedSummary, value); }
public static bool?GetNeedSummary(WPFEntityPropertyViewMeta meta) { return(meta.GetPropertyOrDefault <bool?>(PropertyMetaNeedSummary)); }
/// <summary> /// 为某个属性生成指定类型的属性编辑器 /// </summary> /// <typeparam name="TPropertyEditor">指定使用这种编辑器类型</typeparam> /// <param name="propertyInfo"></param> /// <param name="forList"></param> /// <returns></returns> public TPropertyEditor Create <TPropertyEditor>(WPFEntityPropertyViewMeta propertyInfo, bool forList = true) where TPropertyEditor : PropertyEditor { return(this.Create(typeof(TPropertyEditor), propertyInfo, forList) as TPropertyEditor); }
/// <summary> /// 获取属性的编辑器类型 /// </summary> /// <param name="meta"></param> /// <returns></returns> public static string GetEditorNameOrDefault(this WPFEntityPropertyViewMeta meta) { var value = meta.EditorName; //如果没有显式设置,则根据属性的类型来获取默认编辑器的名称。 if (string.IsNullOrEmpty(value)) { var epm = meta.PropertyMeta; if (epm.ReferenceInfo != null) { return(WPFEditorNames.EntitySelection_DropDown); } var propertyType = TypeHelper.IgnoreNullable(epm.Runtime.PropertyType); if (propertyType.IsEnum) { return(WPFEditorNames.Enum); } if (propertyType == typeof(int)) { value = WPFEditorNames.Int32; } else if (propertyType == typeof(double)) { value = WPFEditorNames.Double; } else if (propertyType == typeof(string)) { value = WPFEditorNames.String; } else if (propertyType == typeof(bool)) { value = WPFEditorNames.Boolean; } else if (propertyType == typeof(DateTime)) { var propertyMeta = meta.PropertyMeta; var mpMeta = propertyMeta.ManagedProperty.GetMeta(propertyMeta.Owner.EntityType) as IPropertyMetadata; switch (mpMeta.DateTimePart) { case DateTimePart.DateTime: value = WPFEditorNames.DateTime; break; case DateTimePart.Date: value = WPFEditorNames.Date; break; case DateTimePart.Time: value = WPFEditorNames.Time; break; default: break; } } else if (propertyType == typeof(NumberRange)) { value = WPFEditorNames.NumberRange; } else if (propertyType == typeof(DateRange)) { value = WPFEditorNames.DateRange; } else { value = propertyType.FullName; } } return(value); }
public static WPFEntityPropertyViewMeta UseMemoEditor(this WPFEntityPropertyViewMeta meta) { return(meta.UseEditor(WPFEditorNames.Memo)); }
public static WPFEntityPropertyViewMeta ShowMemoInDetail(this WPFEntityPropertyViewMeta meta) { return(meta.ShowInDetail(height: 100, columnSpan: 2) .UseEditor(WPFEditorNames.Memo)); }
internal protected virtual void Initialize(WPFEntityPropertyViewMeta propertyInfo) { this.Meta = propertyInfo; }