Exemple #1
0
        /// <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);
        }
Exemple #2
0
        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);
        }