Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
2.1 kB
5
Indexable
        public Agency InsertAgentToGrid(Grid grid)
        {

            DisplayGrid = new Grid();
            
            var headerRowDefinition = new RowDefinition();
            headerRowDefinition.Height = new GridLength(50);
            DisplayGrid.RowDefinitions.Add(headerRowDefinition);

            for (var index = 0; index < GetType().GetProperties().Length; index++)
            {
                var property = GetType().GetProperties()[index];
                var header = new TextBlock();
                var column = new ColumnDefinition();
                header.Text = property.Name;
                header.HorizontalAlignment = HorizontalAlignment.Center;
                header.VerticalAlignment = VerticalAlignment.Center;
                header.FontSize = 16;
                Grid.SetRow(header, 0);
                Grid.SetColumn(header, index);

                DisplayGrid.ColumnDefinitions.Add(column);
                DisplayGrid.Children.Add(header);
            }

            var contentRowDefinition = new RowDefinition();
            contentRowDefinition.Height = new GridLength(50);
            DisplayGrid.RowDefinitions.Add(contentRowDefinition);

            for (var index = 0; index < GetType().GetProperties().Length; index++)
            {
                var propertyValue = GetType().GetProperties()[index];
                var content = new TextBlock();
                content.Text = propertyValue.GetValue(this).ToString();
                content.HorizontalAlignment = HorizontalAlignment.Center;
                content.VerticalAlignment = VerticalAlignment.Center;
                content.FontSize = 12;
                Grid.SetRow(content, 1);
                Grid.SetColumn(content, index);
                DisplayGrid.Children.Add(content);
            }

            DisplayGrid.HorizontalAlignment = HorizontalAlignment.Stretch;
            DisplayGrid.VerticalAlignment = VerticalAlignment.Top;
            DisplayGrid.Margin = new Thickness(0, 25, 0, 0);
            grid.Children.Add(DisplayGrid);

            return this;
        }