public UIElement GenerateUiControl(BaseDto dto, PropertyInfo propertyInfo, Grid grid, int rowIndex)
        {
            CreateLabel(propertyInfo, grid, rowIndex);

            Grid referenceGrid = new Grid();

            referenceGrid.ColumnDefinitions.Add(new ColumnDefinition()
            {
                Width = new GridLength(1, GridUnitType.Star)
            });
            referenceGrid.ColumnDefinitions.Add(new ColumnDefinition()
            {
                Width = GridLength.Auto
            });
            referenceGrid.ColumnDefinitions.Add(new ColumnDefinition()
            {
                Width = GridLength.Auto
            });

            Label referenceLabel = CreateReferenceLabel(dto, propertyInfo);

            Button referenceButton = CreateButton("...", delegate
            {
                IReferenceEditor referenceEditor = CreateReferenceEditor(dto, propertyInfo); //(BaseReferenceEditor)Activator.CreateInstance(Type.GetType(editorAttribute.CompleteAssembly));
                TreeNavigationItem selectedTreeNavigationItem = DialogUtils.OpenReferenceWindow(referenceEditor.GetProposals);
                if (selectedTreeNavigationItem != null)
                {
                    ReferenceString referenceString = new ReferenceString(selectedTreeNavigationItem.Id, selectedTreeNavigationItem.Name);
                    propertyInfo.SetValue(dto, referenceString);
                    referenceLabel.Content = referenceString.GetValue();
                }
            });

            Image image = new Image();

            image.Source = new BitmapImage(RemoveReferenceImage);
            Button removeReferenceButton = CreateButton(image, delegate
            {
                propertyInfo.SetValue(dto, null);
                referenceLabel.Content = string.Empty;
            });

            referenceGrid.Children.Add(referenceLabel);
            referenceGrid.Children.Add(referenceButton);
            referenceGrid.Children.Add(removeReferenceButton);

            Grid.SetColumn(referenceLabel, 0);
            Grid.SetColumn(referenceButton, 1);
            Grid.SetColumn(removeReferenceButton, 2);

            grid.Children.Add(referenceGrid);
            Grid.SetRow(referenceGrid, rowIndex);
            Grid.SetColumn(referenceGrid, 1);

            return(referenceGrid);
        }
Exemple #2
0
        public UIElement GenerateUiControl(BaseDto dto, PropertyInfo propertyInfo, Grid grid, int rowIndex)
        {
            CreateLabel(propertyInfo, grid, rowIndex);

            Grid referenceGrid = new Grid();

            referenceGrid.ColumnDefinitions.Add(new ColumnDefinition()
            {
                Width = new GridLength(1, GridUnitType.Star)
            });
            referenceGrid.ColumnDefinitions.Add(new ColumnDefinition()
            {
                Width = GridLength.Auto
            });
            referenceGrid.ColumnDefinitions.Add(new ColumnDefinition()
            {
                Width = GridLength.Auto
            });

            ListBox referenceList = CreateReferenceList(dto, propertyInfo);

            StackPanel stackPanel = new StackPanel();

            stackPanel.Margin      = new Thickness(10, 0, 5, 0);
            stackPanel.Orientation = Orientation.Vertical;

            Button referenceButton = CreateButton("Add", delegate
            {
                //          ReferenceEdirorAttribute editorAttribute = (ReferenceEdirorAttribute)propertyInfo.GetCustomAttribute(typeof(ReferenceEdirorAttribute));
                IReferenceEditor baseReferenceEditor          = CreateReferenceEditor(dto, propertyInfo); //(BaseReferenceEditor)Activator.CreateInstance(Type.GetType(editorAttribute.CompleteAssembly));
                TreeNavigationItem selectedTreeNavigationItem = DialogUtils.OpenReferenceWindow(baseReferenceEditor.GetProposals);
                if (selectedTreeNavigationItem != null)
                {
                    ReferenceString referenceString = (ReferenceString)propertyInfo.GetValue(dto);
                    if (referenceString == null)
                    {
                        referenceString = new ReferenceString();
                    }
                    referenceString.Append(selectedTreeNavigationItem.Id, selectedTreeNavigationItem.Name);
                    propertyInfo.SetValue(dto, referenceString);
                    referenceList.Items.Add(selectedTreeNavigationItem);
                }
            });

            Button removeReferenceButton = CreateButton("Remove", delegate
            {
                TreeNavigationItem selectedTreeNavigationItem = referenceList.SelectedItem as TreeNavigationItem;
                ReferenceString referenceString = (ReferenceString)propertyInfo.GetValue(dto);
                referenceString.Remove(selectedTreeNavigationItem.Id);
                referenceList.Items.Remove(selectedTreeNavigationItem);
            });

            stackPanel.Children.Add(referenceButton);
            stackPanel.Children.Add(removeReferenceButton);

            referenceGrid.Children.Add(referenceList);
            referenceGrid.Children.Add(stackPanel);

            Grid.SetColumn(referenceList, 0);
            Grid.SetColumn(stackPanel, 1);

            grid.Children.Add(referenceGrid);
            Grid.SetRow(referenceGrid, rowIndex);
            Grid.SetColumn(referenceGrid, 1);

            return(referenceGrid);
        }