Exemplo n.º 1
0
 private IEnumerable<ItemMetadata> GetItemsMetadata(Type type)
 {
     var result = new List<ItemMetadata>();
     var instanceMembers = type.GetMembers(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
     foreach (MemberInfo member in instanceMembers) {
         var configItemAttribute = (ConfigurationItemAttribute)member.GetCustomAttributes(typeof(ConfigurationItemAttribute), true).SingleOrDefault();
         if (configItemAttribute != null) {
             var validatorAttributes = (ValueValidatorAttribute[])member.GetCustomAttributes(typeof(ValueValidatorAttribute), true);
             if (member is FieldInfo) {
                 var field = (FieldInfo)member;
                 var itemMetadata = new ItemMetadata(this, field, configItemAttribute, validatorAttributes);
                 result.Add(itemMetadata);
             } else if (member is PropertyInfo) {
                 var property = (PropertyInfo)member;
                 var itemMetadata = new ItemMetadata(this, property, configItemAttribute, validatorAttributes);
                 result.Add(itemMetadata);
             }
         }
     }
     return result;
 }
Exemplo n.º 2
0
        private FrameworkElement CreateHeaderCell(ItemMetadata itemMetadata)
        {
            TextBlock uiText = new TextBlock();
            uiText.Text = itemMetadata.UserName;
            uiText.ToolTip = itemMetadata.UserDescription;
            uiText.HorizontalAlignment = HorizontalAlignment.Right;
            uiText.FontWeight = FontWeights.Bold;
            Grid.SetColumn(uiText, 1);

            Grid result = new Grid() {
                Margin = new Thickness(10, 8, 5, 0),
                VerticalAlignment = VerticalAlignment.Top,
                ColumnDefinitions = {
                    new ColumnDefinition { Width = new GridLength(1, GridUnitType.Auto) },
                    new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }
                },
                Children = { uiText }
            };

            if ((itemMetadata.UserDescription != null) && (itemMetadata.UserDescription.Trim().Length > 0)) {
                ToolTip helpToolTip = new ToolTip {
                    Background = new LinearGradientBrush {
                        GradientStops = {
                            new GradientStop(Colors.Yellow, -2),
                            new GradientStop(Colors.LightYellow, 1),
                        }
                    },
                    BorderBrush = Brushes.LightGray,
                    BorderThickness = new Thickness(1),
                    Content = new TextBlock {
                        Text = itemMetadata.UserDescription,
                        Margin = new Thickness(3),
                        FontSize = 14,
                        Foreground = Brushes.Black,
                        FontWeight = FontWeights.SemiBold
                    }
                };
                
                Image uiHelp = new Image {
                    ToolTip = helpToolTip,
                    Source = new System.Windows.Media.Imaging.BitmapImage(new Uri("pack://application:,,,/ObjectConfigurator;component/Resources/Help-icon.png")),
                    Margin = new Thickness(0, 0, 5, 0),
                    Height = 12
                };
                ToolTipService.SetInitialShowDelay(uiHelp, 0);
                ToolTipService.SetShowDuration(uiHelp, int.MaxValue);
                Grid.SetColumn(uiHelp, 0);
                result.Children.Add(uiHelp);
            }

            return result;
        }