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); }
private Label CreateReferenceLabel(BaseDto dto, PropertyInfo propertyInfo) { Label label = new Label(); label.Margin = new Thickness(0, 2, 0, 2); ReferenceString referenceString = (ReferenceString)propertyInfo.GetValue(dto); if (referenceString != null) { label.Content = referenceString.GetValue(); } return(label); }
public void Convert(Connection connection, BaseEntity sourceEntity, BaseDto dto, PropertyInfo sourcePropertyInfo, ReferenceAttribute referenceAttribute, ReferenceString referenceString) { PropertyInfo targetProperty = sourceEntity.GetType().GetProperty(ReferenceConversionUtils.GetReferencedId(referenceAttribute)); if (referenceString == null || string.IsNullOrEmpty(referenceString.GetValue())) { targetProperty.SetValue(sourceEntity, null); } else { targetProperty.SetValue(sourceEntity, referenceString.GetId()); } }
public static MvcHtmlString LocalizedDisplayFor <T, U>(this HtmlHelper <T> htmlHelper, Expression <Func <T, U> > expression, string defaultValue = null) { ModelMetadata expressionModelMetadata = ModelMetadata.FromLambdaExpression(expression, htmlHelper.ViewData); if (expressionModelMetadata.Model == null) { return(MvcHtmlString.Create(defaultValue)); } if (expressionModelMetadata.Model is ReferenceString) { ReferenceString referenceString = expressionModelMetadata.Model as ReferenceString; return(MvcHtmlString.Create(referenceString.GetValue())); } return(DisplayExtensions.DisplayFor(htmlHelper, expression)); }