Esempio n. 1
0
        void SourceChanged(object source)
        {
            if (!(source is BMTask))
            {
                throw new InvalidOperationException("Can only assign a BMTask derived class to Source");
            }
            BMTask task = (BMTask)source;

            List <PropertyInfo> propertyList = task.GetType().GetProperties().
                                               Where(pi => pi.GetCustomAttributesData().All(cad => cad.Constructor.DeclaringType != typeof(XmlIgnoreAttribute))).ToList();

            PropertyGrid.Children.Clear();
            PropertyGrid.RowDefinitions.Clear();
            for (int index = 0; index < propertyList.Count; index++)
            {
                PropertyGrid.RowDefinitions.Add(new RowDefinition()
                {
                    Height = new GridLength(22)
                });
                var propNameText = new TextBlock()
                {
                    Text   = SpacifierConverter.GetSpaciousString(propertyList[index].Name),
                    Margin = new Thickness(2, 0, 2, 0)
                };
                Grid.SetRow(propNameText, index);
                PropertyGrid.Children.Add(propNameText);

                Control propEdit;
                // check if the property has CustomTaskEditControl attribute attached
                CustomTaskEditControlAttribute customControlAttr =
                    (CustomTaskEditControlAttribute)propertyList[index].GetCustomAttributes(typeof(CustomTaskEditControlAttribute), false).FirstOrDefault();
                if (customControlAttr != null)
                {
                    propEdit = (Control)Activator.CreateInstance(customControlAttr.ControlType);
                    if (!(propEdit is ICustomTaskEditControlDataBound))
                    {
                        throw new InvalidOperationException("CustomTaskEditControl must implement the ICustomTaskEditControlDataBound interface");
                    }
                    ((ICustomTaskEditControlDataBound)propEdit).SetValue(propertyList[index].GetValue(task, null));
                    ((ICustomTaskEditControlDataBound)propEdit).SetBinding(task, propertyList[index].Name);
                }
                else // no custom controls attached to property so load the default control for the property type
                {
                    propEdit = GetControlForType(propertyList[index].PropertyType, propertyList[index].GetValue(task, null));
                }
                propEdit.Margin = new Thickness(0, 1, 0, 1);
                propEdit.Tag    = new { Task = task, Property = propertyList[index] };

                Grid.SetColumn((UIElement)propEdit, 1);
                Grid.SetRow((UIElement)propEdit, index);
                PropertyGrid.Children.Add((UIElement)propEdit);
            }
        }
Esempio n. 2
0
        public AccountConfigUserControl()
        {
            InitializeComponent();
            IsEditing = false;
            // Get list of tasks via reflection
            List <Type> taskTypes = Assembly.GetExecutingAssembly().GetTypes().Where(t => typeof(BMTask).IsAssignableFrom(t) && t != typeof(BMTask)).ToList();

            foreach (var type in taskTypes)
            {
                ListBoxItem item = new ListBoxItem();
                BMTask      task = (BMTask)Activator.CreateInstance(type);
                item.Content = SpacifierConverter.GetSpaciousString(task.Name);
                item.Tag     = type;
                item.ToolTip = task.Help;
                TaskList.Items.Add(item);
            }

            ProfileTaskList.ContextMenuOpening += (sender, e) => { if (ProfileTaskList.SelectedItem == null)
                                                                   {
                                                                       e.Handled = true;
                                                                   }
            };
            RegionCombo.ItemsSource = Enum.GetValues(typeof(WowSettings.WowRegion));
        }