public MetadataPropertyView(MetadataPropertyViewModel viewModel) : this()
 {
     this.DataContext = viewModel;
 }
        private UIElement BuildEntityView(Entity entity)
        {
            Expander expander = new Expander()
            {
                IsExpanded      = false,
                ExpandDirection = ExpandDirection.Down,
                Header          = new TextBlock()
                {
                    Text              = entity.Name + ((entity == this.model) ? " (собственные свойства)" : string.Empty),
                    Margin            = new Thickness(4),
                    FontSize          = 14,
                    FontWeight        = FontWeights.Bold,
                    VerticalAlignment = VerticalAlignment.Center
                },
                Content = new ScrollViewer()
                {
                    MaxHeight = 250,
                    VerticalScrollBarVisibility   = ScrollBarVisibility.Auto,
                    HorizontalScrollBarVisibility = ScrollBarVisibility.Auto
                }
            };

            Grid grid = new Grid();

            grid.ColumnDefinitions.Add(new ColumnDefinition()
            {
                MinWidth = 100, Width = GridLength.Auto
            });
            grid.ColumnDefinitions.Add(new ColumnDefinition()
            {
                MinWidth = 100, Width = GridLength.Auto
            });

            int rowIndex = 0;

            foreach (Property property in entity.Properties
                     .Where(p => !p.IsAbstract)
                     .OrderBy(p => p.Ordinal))
            {
                grid.RowDefinitions.Add(new RowDefinition()
                {
                    Height = GridLength.Auto
                });

                TextBlock textBlock = new TextBlock()
                {
                    Text                = $"{property.Name}:",
                    Margin              = new Thickness(5),
                    VerticalAlignment   = VerticalAlignment.Center,
                    HorizontalAlignment = HorizontalAlignment.Left
                };
                Grid.SetRow(textBlock, rowIndex);
                Grid.SetColumn(textBlock, 0);
                grid.Children.Add(textBlock);

                object value = null;
                if (property.Relations.Count > 0)
                {
                    value = Entity.GetDefaultValue(property.Relations[0].Entity);
                }

                MetadataPropertyViewModel propertyViewModel = new MetadataPropertyViewModel(this, property, value);
                MetadataPropertyView      propertyView      = new MetadataPropertyView(propertyViewModel);
                Grid.SetRow(propertyView, rowIndex);
                Grid.SetColumn(propertyView, 1);
                grid.Children.Add(propertyView);

                rowIndex++;
            }

            ScrollViewer sv = (ScrollViewer)expander.Content;

            sv.Content = grid;
            return(expander);
        }