Пример #1
0
        internal void UpdateGridRowColumn()
        {
            var attr = Object == null ? new GridDescriptorAttribute() :
                       Object.GetType().GetAttribute <GridDescriptorAttribute>();

            if (attr == null)
            {
                attr = new GridDescriptorAttribute();
            }

            int column = attr.Column;
            int row    = (_properties.Count - 1) / column + 1;

            GridColumnCount = column;
            GridRowCount    = row;

            for (int i = 0; i < row; i++)
            {
                for (int j = 0; j < column; j++)
                {
                    var index = i * column + j;
                    if (index >= _properties.Count)
                    {
                        continue;
                    }

                    var prop = _properties[index];
                    var pda  = prop.PropertyInfo.GetAttribute <PropertyDescriptorAttribute>();
                    if (pda == null)
                    {
                        pda = new PropertyDescriptorAttribute();
                    }

                    Grid.SetRow(prop.Designer, i);
                    Grid.SetColumn(prop.Designer, j * 2);
                    Grid.SetColumnSpan(prop.Designer, pda.ColumnSpan * 2 - 1);

                    if (pda.Height > 0)
                    {
                        (prop.Designer as FrameworkElement).Height = pda.Height;
                    }
                }
            }
        }
Пример #2
0
        private void OnCompletedGrouping(List <PropertyDescriptor> metas)
        {
            metas.ForEach(c =>
            {
                var info = c.Object.GetType().GetProperty(c.Name);

                var attr = info.GetAttribute <PropertyDescriptorAttribute>();
                if (attr == null)
                {
                    attr = new PropertyDescriptorAttribute();
                }
                if (attr.Gallery.IsNullOrBlank())
                {
                    attr.Gallery = "默认";
                }

                var container = GetPropertyContainer(attr);

                if (c.BindingExpression != null && pg.IsGroupingEnabled && pg.Editable)
                {
                    tabs[attr.Gallery].BindingGroup.BindingExpressions.Add(c.BindingExpression);
                }

                container.Properties.Add(c);
            });

            if (pg.ContainerType == ePropertyGridContainerType.Grid ||
                pg.ContainerType == ePropertyGridContainerType.Form ||
                pg.ContainerType == ePropertyGridContainerType.FormWithoutScrollViewer ||
                pg.ContainerType == ePropertyGridContainerType.Details ||
                pg.ContainerType == ePropertyGridContainerType.DetailsWithoutScrollViewer)
            {
                var attr = lastObjectType == null ? new GridDescriptorAttribute() :
                           lastObjectType.GetAttribute <GridDescriptorAttribute>();

                if (attr == null)
                {
                    attr = new GridDescriptorAttribute();
                }

                foreach (var tab in tabs)
                {
                    tab.Value.ContainerType = pg.ContainerType;
                    foreach (var cata in tab.Value.Catalogs)
                    {
                        cata.GridColumnSpacing = pg.GridColumnSpacing;
                        cata.UpdateGridRowColumn(attr.Column);
                    }
                }
            }

            pg.tabControl.HeaderVisibility =
                tabs.Count > 1 ? Visibility.Visible : Visibility.Collapsed;

            if (pg.tabControl.HeaderVisibility != Visibility.Visible)
            {
                pg.tabControl.BorderThickness = new Thickness(0);
            }
            else if (pg.tabControl.Direction == eDirection.Top)
            {
                pg.tabControl.BorderThickness = new Thickness(0, 1, 0, 0);
            }
            else if (pg.tabControl.Direction == eDirection.Left)
            {
                pg.tabControl.BorderThickness = new Thickness(1, 0, 0, 0);
            }
            else if (pg.tabControl.Direction == eDirection.Right)
            {
                pg.tabControl.BorderThickness = new Thickness(0, 0, 1, 0);
            }
            else if (pg.tabControl.Direction == eDirection.Bottom)
            {
                pg.tabControl.BorderThickness = new Thickness(0, 0, 0, 1);
            }

            var contentMargin = pg.tabControl.HeaderVisibility ==
                                Visibility.Visible ? new Thickness(0, 5, 0, 5) : new Thickness(0);

            foreach (var tab in tabs)
            {
                tab.Value.Margin = contentMargin;
                tab.Value.Catalogs[0].HeaderVisibility =
                    tab.Value.Catalogs.Count > 1 ? Visibility.Visible : Visibility.Collapsed;

                tab.Value.InstallSelectedIndexSyncHandler();
            }

            pg.tabControl.SelectedIndex = -1;
            pg.tabControl.SelectedIndex = 0;
        }