Beispiel #1
0
        protected override void OnVisualParentChanged(DependencyObject oldParent)
        {
            base.OnVisualParentChanged(oldParent);

            //在变更父对象时,同步 Form 属性
            if (this._form != null)
            {
                this._form.Editors.Remove(this);
                this._form = null;
            }

            this.InitForm();
        }
Beispiel #2
0
 /// <summary>
 /// 设置新的 Form
 /// </summary>
 private void InitForm()
 {
     if (this._form == null)
     {
         this._form = Form.GetForm(this);
         if (this._form != null) { this._form.Editors.Add(this); }
     }
 }
Beispiel #3
0
        /// <summary>
        /// 生成一个AutoGrid,用于承载所有的字段显示控件。
        /// </summary>
        /// <param name="detailView">逻辑视图</param>
        /// <returns></returns>
        public Form CreateDetailPanel(DetailLogicalView detailView)
        {
            if (detailView == null) throw new ArgumentNullException("detailView");

            Form form = null;

            var meta = detailView.Meta;
            if (meta.DetailPanelType == null)
            {
                /*********************** 代码块解释 *********************************
                 * 表单自动生成解释:
                 *
                 * 首先,所有属性分组,如果:
                 * 1. 没有分组时,根据 DetailLayoutMode 的值,分以下两种情况来生成表单:
                 * * 使用 AutoGrid 作为 Editor 的容器,以保证每个 Editor 有动态的宽度。
                 * * 使用 WrapPanel 作为 Editor 的容器,使得实现 Editor 的自动换行。(此时 Editor 应该有最小的宽度。)
                 * 2. 如果分为多个组,则使用 TabControl 或者使用 GroupBox 把每个组分开生成,每个组则都使用上一条算法进行生成。
                 *
                 * 最外围的容器是 Form 控件,它的 VerticalScrollBarVisibility 在样式中将被设置为 Auto,
                 * 而 HorizontalScrollBarVisibility 则为 Disable。
                 *
                 * 这样,整体设计上,保证竖直方向上有滚动条,水平方向上是动态宽度或动态换行。
                **********************************************************************/

                form = new Form();

                var groups = meta.DetailGroups;
                if (groups.Count > 0)
                {
                    form.Content = this.GenerateGroups(detailView, groups);
                }
                else
                {
                    var properties = OrderedDetailProperties(meta.EntityProperties);
                    form.Content = this.GenerateEditors(detailView, properties, meta.DetailLayoutMode);
                }

                //var groups = meta.OrderedEntityProperties().Where(pv => pv.CanShowIn(ShowInWhere.Detail))
                //    .GroupBy(pv => pv.DetailGroupName).ToArray();
                //if (groups.Length == 0) throw new InvalidOperationException(meta.EntityType.FullName + " 没有属性在表单中显示时,不能生成表单控件。");

                //if (groups.Length == 1)
                //{
                //    form.Content = this.GenerateEditors(detailView, groups[0]);
                //}
                //else
                //{
                //    form.Content = this.GenerateGroups(detailView, groups);
                //}
            }
            //自定义表单布局
            else
            {
                form = Activator.CreateInstance(meta.DetailPanelType) as Form;
                if (form == null) throw new InvalidProgramException("自定义面板必须是 Form 元素。");
            }

            form.DetailView = detailView;

            //即时调用 EditorHost 的 ApplyTemplate 方法,
            //可以使 EditorHost 即时生成 PropertyEditor,而不是等到界面 Loaded 时再生成。
            ApplyEditorHostTemplate(form);

            return form;
        }