Пример #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 PropertyGridCatalogMetadata GetPropertyContainer(PropertyDescriptorAttribute attr)
        {
            if (!tabs.ContainsKey(attr.Gallery))
            {
                var content = new PropertyGridTabItemContent()
                {
                    PropertyGrid = pg
                };
                var item = new ListTabItem()
                {
                    Name   = attr.Gallery.Replace(' ', '_'),
                    Header = new TextBox()
                    {
                        Text    = attr.Gallery,
                        ToolTip = attr.Gallery,
                    },
                    Content = content,
                };

                tabs[attr.Gallery] = content;
                pg.tabControl.Items.Add(item);
            }

            var tab = tabs[attr.Gallery];

            if (!tab.Catalogs.Any(c => c.Name == attr.Catalog))
            {
                tab.Catalogs.Add(new PropertyGridCatalogMetadata()
                {
                    Name         = attr.Catalog,
                    Image        = attr.CatalogImage16.IsNullOrBlank() ? null : BitmapFrame.Create(new Uri(attr.CatalogImage16)),
                    PropertyGrid = pg,
                });
            }

            return(tab.Catalogs.FirstOrDefault(c => c.Name == attr.Catalog));
        }
        internal void UpdateGridRowColumn(int cntCol)
        {
            DisplayItems.Clear();

            if (PropertyGrid.ContainerType == ePropertyGridContainerType.Details ||
                PropertyGrid.ContainerType == ePropertyGridContainerType.DetailsWithoutScrollViewer)
            {
                int row = 0;
                int col = 0;
                for (int i = 0; i < Properties.Count; i++)
                {
                    var prop = Properties[i];
                    var pda  = prop.PropertyInfo.GetAttribute <PropertyDescriptorAttribute>();
                    if (pda == null)
                    {
                        pda = new PropertyDescriptorAttribute();
                    }

                    if (col >= cntCol)
                    {
                        row++;
                        col = 0;
                    }

                    Grid.SetRow(prop.Designer, row * 2);
                    Grid.SetColumn(prop.Designer, col * 2);

                    var colSpan = pda.ColumnSpan;
                    Grid.SetColumnSpan(prop.Designer, colSpan * 2 - 1);

                    col += colSpan;

                    if (pda.Height > 0)
                    {
                        (prop.Designer as FrameworkElement).Height = pda.Height;
                    }
                }

                GridColumnCount = cntCol;
                GridRowCount    = row + 1;

                foreach (var item in Properties)
                {
                    DisplayItems.Add(item);
                }

                for (int i = 0; i < row; i++)
                {
                    var separator = new SeparatorH();
                    separator.Margin = new Thickness(0);
                    Grid.SetRow(separator, i * 2 + 1);
                    Grid.SetColumnSpan(separator, cntCol * 2 - 1);

                    DisplayItems.Add(new PropertyGridSeparatorItem {
                        Designer = separator
                    });
                }
            }
            else
            {
                int row = 0;
                int col = 0;
                for (int i = 0; i < Properties.Count; i++)
                {
                    var prop = Properties[i];
                    var pda  = prop.PropertyInfo.GetAttribute <PropertyDescriptorAttribute>();
                    if (pda == null)
                    {
                        pda = new PropertyDescriptorAttribute();
                    }

                    if (col >= cntCol)
                    {
                        row++;
                        col = 0;
                    }

                    Grid.SetRow(prop.Designer, row);
                    Grid.SetColumn(prop.Designer, col * 2);

                    var colSpan = pda.ColumnSpan;
                    Grid.SetColumnSpan(prop.Designer, colSpan * 2 - 1);

                    col += colSpan;

                    if (pda.Height > 0)
                    {
                        (prop.Designer as FrameworkElement).Height = pda.Height;
                    }
                }

                GridColumnCount = cntCol;
                GridRowCount    = row + 1;
            }
        }
Пример #4
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;
        }