protected virtual FrameworkElement CreateListControl(PropertyItem property)
        {
            var c = new ListBox();

            c.SetBinding(ItemsControl.ItemsSourceProperty, property.CreateBinding());
            return(c);
        }
示例#2
0
        private FrameworkElement CreateBindableComboBoxControl(PropertyItem pi, string lookupKey)
        {
            var cbx = new ComboBox();

            var itemsSourceBinding = pi.CreateOneWayBinding();

            itemsSourceBinding.Path   = null;
            itemsSourceBinding.Source = pi.ItemsSource;
            cbx.SetBinding(ItemsControl.ItemsSourceProperty, itemsSourceBinding);

            ReferenceLookupList.RegisterListUpdateEventHandler(lookupKey, (sender, args) =>
            {
                var list = ReferenceLookupList.GetCompleteList(lookupKey);
                var itemsSourceBinding1    = pi.CreateOneWayBinding();
                itemsSourceBinding1.Path   = null;
                itemsSourceBinding1.Source = list;
                cbx.SetBinding(ItemsControl.ItemsSourceProperty, itemsSourceBinding1);
            });

            var selectedItemBinding = pi.CreateBinding();

            selectedItemBinding.Mode = BindingMode.TwoWay;
            //selectedItemBinding.Path = new PropertyPath("Selected");
            cbx.SetBinding(Selector.SelectedItemProperty, selectedItemBinding);

            return(cbx);
        }
示例#3
0
        private FrameworkElement CreateNestedPropertyGridsControl(PropertyItem pi)
        {
            const string Xaml = @"<Expander xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'
             xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'
             xmlns:mc='http://schemas.openxmlformats.org/markup-compatibility/2006' 
             xmlns:Wpf='clr-namespace:TAC.Wpf;assembly=TACWpf'>
                <ItemsControl Name ='ItemPanel' >
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <Wpf:PropertyControlEx DefaultTabName='Item' SelectedObject='{Binding }' Margin='8' Padding='12'/>
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>
             </Expander>";

            var sr     = new StringReader(Xaml);
            var reader = XmlReader.Create(sr);
            var retval = (FrameworkElement)XamlReader.Load(reader);

            var ic = (ItemsControl)retval.FindName("ItemPanel");

            if (ic != null)
            {
                ic.SetBinding(ItemsControl.ItemsSourceProperty, pi.CreateBinding());
            }

            return(retval);
        }
示例#4
0
        protected virtual FrameworkElement CreateCommandLinkControl(PropertyItem property)
        {
            var commandAtt = property.Descriptor.Attributes.OfType <Attribute>().FirstOrDefault(att => att is IPrefabCommand) as IPrefabCommand;


            var c = new CommandLinkBlock {
                PrefabInvocation = commandAtt, VerticalAlignment = VerticalAlignment.Center, TextDecorations = TextDecorations.Underline
            };

            if (property.GetAttribute <AssignCommandDataAttribute>() != null)
            {
                c.CommandDataAssignment = true;
            }


            c.SetBinding(TextBlock.TextProperty, new System.Windows.Data.Binding(property.Descriptor.Name));
            c.SetBinding(CommandLinkBlock.CommandProperty, property.CreateBinding());

            if (c.CommandDataAssignment)
            {
                c.SetBinding(CommandLinkBlock.CommandDataProperty,
                             new System.Windows.Data.Binding("SelectedObject")
                {
                    RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(PropertyControlEx), 1), Mode = BindingMode.OneWay
                });
            }

            return(c);
        }
        protected virtual FrameworkElement CreateCommandControl(PropertyItem property)
        {
            var c = new Button();

            c.SetBinding(ButtonBase.CommandProperty, property.CreateBinding());
            return(c);
        }
示例#6
0
        private FrameworkElement CreateBindableMultipleSelectControl(PropertyItem pi, string lookupKey)
        {
            var control = new ListBoxWrapper();

            var data = pi.Converter.Convert(pi.ItemsSource, typeof(IList <string>), null, null) as IList <string>;

            control.AllItems = data;
            control.InitSelectedItemsViewModel = null;


            ReferenceLookupList.RegisterListUpdateEventHandler(lookupKey, (sender, args) =>
            {
                var list         = ReferenceLookupList.GetCompleteList(lookupKey);
                var data1        = pi.Converter.Convert(list, typeof(IList <string>), null, null) as IList <string>;
                control.AllItems = data1;
            });

            var selectedItemBinding = pi.CreateBinding();

            selectedItemBinding.Mode = BindingMode.TwoWay;
            control.SetBinding(ListBoxWrapper.SelectedItemsProperty, selectedItemBinding);

            //var initSelectedBinding = pi.CreateOneWayBinding();
            //control.SetBinding(ListBoxWrapper.InitSelectedItemsProperty, initSelectedBinding);

            return(control);
            //return base.CreateDefaultControl(pi);
        }
        protected override FrameworkElement CreateEnumControl(PropertyItem property, PropertyControlFactoryOptions options)
        {
            var enumType = TypeHelper.GetEnumType(property.Descriptor.PropertyType);

            var c = new EnumCombo {
                Enum = enumType
            };

            c.SetBinding(Selector.SelectedValueProperty, property.CreateBinding());
            return(c);
        }
示例#8
0
        public override FrameworkElement CreateControl(PropertyItem property, PropertyControlFactoryOptions options)
        {
            if (typeof(ICommand).IsAssignableFrom(property.ActualPropertyType))
            {
                property.HeaderPlacement = HeaderPlacement.Hidden;

                var result = new Button
                {
                    Content = property.DisplayName
                };
                result.SetBinding(ButtonBase.CommandProperty, property.CreateBinding());
                return(result);
            }

            return(base.CreateControl(property, options));
        }
示例#9
0
        protected override FrameworkElement CreateDefaultControl(PropertyItem property)
        {
            var controlAttribute = property.GetAttribute <CustomEditorAttribute>();

            if (controlAttribute != null)
            {
                var control = (FrameworkElement)Activator.CreateInstance(controlAttribute.ControlType);
                control.VerticalAlignment = VerticalAlignment.Center;
                control.SetBinding(FrameworkElement.DataContextProperty, property.CreateBinding());

                return(control);
            }

            property.AutoUpdateText = true;
            return(base.CreateDefaultControl(property));
        }
示例#10
0
        protected virtual FrameworkElement CreateNestedPropertyGridControl(PropertyItem pi)
        {
            const string Xaml = @"<Expander xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'
             xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'
             xmlns:mc='http://schemas.openxmlformats.org/markup-compatibility/2006' 
             xmlns:Wpf='clr-namespace:TAC.Wpf;assembly=TACWpf'>
                            <Wpf:PropertyControlEx Name='NestedPanel' Margin='8' Padding='12'/>
             </Expander>";

            var sr     = new StringReader(Xaml);
            var reader = XmlReader.Create(sr);
            var retval = (FrameworkElement)XamlReader.Load(reader);

            var pc = (PropertyControlEx)retval.FindName("NestedPanel");

            if (pc != null)
            {
                pc.SetBinding(PropertyControl.SelectedObjectProperty, pi.CreateBinding());
            }

            return(retval);
        }
        /// <summary>
        /// Creates the slider control.
        /// </summary>
        /// <param name="property">The property.</param>
        /// <returns>
        /// The control.
        /// </returns>
        protected virtual FrameworkElement CreateSliderControl(PropertyItem property)
        {
            var g = new Grid();
            g.ColumnDefinitions.Add(
                new System.Windows.Controls.ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) });
            g.ColumnDefinitions.Add(
                new System.Windows.Controls.ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) });
            var s = new Slider
                {
                    Minimum = property.SliderMinimum,
                    Maximum = property.SliderMaximum,
                    SmallChange = property.SliderSmallChange,
                    LargeChange = property.SliderLargeChange,
                    TickFrequency = property.SliderTickFrequency,
                    IsSnapToTickEnabled = property.SliderSnapToTicks
                };
            s.SetBinding(RangeBase.ValueProperty, property.CreateBinding());
            g.Children.Add(s);

            var trigger = property.AutoUpdateText ? UpdateSourceTrigger.PropertyChanged : UpdateSourceTrigger.Default;
            var c = new TextBoxEx { IsReadOnly = property.Descriptor.IsReadOnly };

            var formatString = property.FormatString;
            if (formatString != null && !formatString.StartsWith("{"))
            {
                formatString = "{0:" + formatString + "}";
            }

            var binding = property.CreateBinding();
            binding.StringFormat = formatString;
            binding.UpdateSourceTrigger = trigger;

            c.SetBinding(TextBox.TextProperty, binding);

            Grid.SetColumn(c, 1);
            g.Children.Add(c);

            return g;
        }
 /// <summary>
 /// Creates the link control.
 /// </summary>
 /// <param name="property">The property.</param>
 /// <returns>
 /// The control.
 /// </returns>
 protected virtual FrameworkElement CreateLinkControl(PropertyItem property)
 {
     var c = new LinkBlock { VerticalAlignment = VerticalAlignment.Center };
     c.SetBinding(TextBlock.TextProperty, new Binding(property.Descriptor.Name));
     c.SetBinding(LinkBlock.NavigateUriProperty, property.CreateBinding());
     return c;
 }
 /// <summary>
 /// Creates the password control.
 /// </summary>
 /// <param name="property">The property.</param>
 /// <returns>
 /// The control.
 /// </returns>
 protected virtual FrameworkElement CreatePasswordControl(PropertyItem property)
 {
     var c = new PasswordBox();
     PasswordHelper.SetAttach(c, true);
     c.SetBinding(PasswordHelper.PasswordProperty, property.CreateBinding());
     return c;
 }
        /// <summary>
        /// Creates the combo box control.
        /// </summary>
        /// <param name="property">
        /// The property.
        /// </param>
        /// <returns>
        /// The control.
        /// </returns>
        protected FrameworkElement CreateComboBoxControl(PropertyItem property)
        {
            var c = new ComboBox { IsEditable = property.IsEditable };
            c.SetBinding(ItemsControl.ItemsSourceProperty, new Binding(property.ItemsSourceDescriptor.Name));

            c.SetBinding(
                property.IsEditable ? ComboBox.TextProperty : Selector.SelectedValueProperty, property.CreateBinding());

            return c;
        }
        /// <summary>
        /// Creates the checkbox control.
        /// </summary>
        /// <param name="property">The property.</param>
        /// <returns>
        /// The control.
        /// </returns>
        protected virtual FrameworkElement CreateBoolControl(PropertyItem property)
        {
            if (property.Descriptor.IsReadOnly())
            {
                var cm = new CheckMark
                {
                    VerticalAlignment = VerticalAlignment.Center,
                    HorizontalAlignment = HorizontalAlignment.Left
                };
                cm.SetBinding(CheckMark.IsCheckedProperty, property.CreateBinding());
                return cm;
            }

            var c = new CheckBox
                {
                    VerticalAlignment = VerticalAlignment.Center,
                    HorizontalAlignment = HorizontalAlignment.Left
                };

            c.SetBinding(ToggleButton.IsCheckedProperty, property.CreateBinding());
            return c;
        }
        /// <summary>
        /// Creates the combo box control.
        /// </summary>
        /// <param name="property">The property.</param>
        /// <returns>
        /// The control.
        /// </returns>
        protected virtual FrameworkElement CreateComboBoxControl(PropertyItem property)
        {
            var c = new ComboBox { IsEditable = property.IsEditable, ItemsSource = property.ItemsSource, VerticalContentAlignment = VerticalAlignment.Center };
            if (property.ItemsSourceDescriptor != null)
            {
                c.SetBinding(ItemsControl.ItemsSourceProperty, new Binding(property.ItemsSourceDescriptor.Name));
            }

            c.SelectedValuePath = property.SelectedValuePath;

            c.SetBinding(property.IsEditable ? ComboBox.TextProperty : Selector.SelectedValueProperty, property.CreateBinding());

            return c;
        }
        /// <summary>
        /// Creates the default control.
        /// </summary>
        /// <param name="property">
        /// The property.
        /// </param>
        /// <returns>
        /// The control.
        /// </returns>
        protected FrameworkElement CreateDefaultControl(PropertyItem property)
        {
            // TextBox is the default control
            var trigger = property.AutoUpdateText ? UpdateSourceTrigger.PropertyChanged : UpdateSourceTrigger.Default;
            var c = new TextBox
                {
                    AcceptsReturn = property.AcceptsReturn,
                    MaxLength = property.MaxLength,
                    IsReadOnly = property.Descriptor.IsReadOnly,
                    TextWrapping = property.TextWrapping,
                    VerticalScrollBarVisibility = ScrollBarVisibility.Auto
                };

            c.SetBinding(TextBox.TextProperty, property.CreateBinding(trigger));
            return c;
        }
 /// <summary>
 /// Creates the directory path control.
 /// </summary>
 /// <param name="property">The property.</param>
 /// <returns>
 /// The control.
 /// </returns>
 protected virtual FrameworkElement CreateDirectoryPathControl(PropertyItem property)
 {
     var c = new DirectoryPicker { FolderBrowserDialogService = this.FolderBrowserDialogService };
     var trigger = property.AutoUpdateText ? UpdateSourceTrigger.PropertyChanged : UpdateSourceTrigger.Default;
     c.SetBinding(DirectoryPicker.DirectoryProperty, property.CreateBinding(trigger));
     return c;
 }
        /// <summary>
        /// Creates the grid control.
        /// </summary>
        /// <param name="property">
        /// The property.
        /// </param>
        /// <returns>
        /// The control.
        /// </returns>
        protected FrameworkElement CreateGridControl(PropertyItem property)
        {
            var c = new SimpleGrid { CanDelete = property.ListCanRemove, CanInsert = property.ListCanAdd };

            var glc = new GridLengthConverter();
            foreach (var ca in property.Columns.OrderBy(cd => cd.ColumnIndex))
            {
                var cd = new ColumnDefinition
                    {
                        DataField = ca.PropertyName,
                        Header = ca.Header,
                        FormatString = ca.FormatString,
                        Width = (GridLength)glc.ConvertFromInvariantString(ca.Width)
                    };
                switch (ca.Alignment.ToString().ToUpper())
                {
                    case "L":
                        cd.HorizontalAlignment = HorizontalAlignment.Left;
                        break;
                    case "R":
                        cd.HorizontalAlignment = HorizontalAlignment.Right;
                        break;
                    default:
                        cd.HorizontalAlignment = HorizontalAlignment.Center;
                        break;
                }

                c.ColumnDefinitions.Add(cd);
            }

            c.SetBinding(SimpleGrid.ContentProperty, property.CreateBinding());
            return c;
        }
        /// <summary>
        /// Creates the default control.
        /// </summary>
        /// <param name="property">The property.</param>
        /// <returns>
        /// The control.
        /// </returns>
        protected virtual FrameworkElement CreateDefaultControl(PropertyItem property)
        {
            // TextBox is the default control
            var trigger = property.AutoUpdateText ? UpdateSourceTrigger.PropertyChanged : UpdateSourceTrigger.Default;
            var c = new TextBoxEx
                {
                    AcceptsReturn = property.AcceptsReturn,
                    MaxLength = property.MaxLength,
                    IsReadOnly = property.IsReadOnly,
                    TextWrapping = property.TextWrapping,
                    VerticalScrollBarVisibility = ScrollBarVisibility.Auto,
                    VerticalContentAlignment = property.AcceptsReturn ? VerticalAlignment.Top : VerticalAlignment.Center
                };

            if (property.FontFamily != null)
            {
                c.FontFamily = new FontFamily(property.FontFamily);
            }

            if (!double.IsNaN(property.FontSize))
            {
                c.FontSize = property.FontSize;
            }

            if (property.IsReadOnly)
            {
                // c.Opacity = 0.8;
                c.Foreground = Brushes.RoyalBlue;
            }

            var binding = property.CreateBinding(trigger);
            if (property.ActualPropertyType != typeof(string) && IsNullable(property.ActualPropertyType))
            {
                // Empty values should set the source to null
                // Set the value that is used in the target when the value of the source is null.
                binding.TargetNullValue = string.Empty;
            }

            c.SetBinding(TextBox.TextProperty, binding);
            return c;
        }
 /// <summary>
 /// Creates a dictionary control.
 /// </summary>
 /// <param name="property">The property.</param>
 /// <returns>
 /// The control.
 /// </returns>
 protected virtual FrameworkElement CreateDictionaryControl(PropertyItem property)
 {
     // todo
     var c = new ComboBox();
     c.SetBinding(ItemsControl.ItemsSourceProperty, property.CreateBinding());
     return c;
 }
 /// <summary>
 /// Creates the date time control.
 /// </summary>
 /// <param name="property">The property.</param>
 /// <returns>
 /// The control.
 /// </returns>
 protected virtual FrameworkElement CreateDateTimeControl(PropertyItem property)
 {
     var c = new DatePicker();
     c.SetBinding(DatePicker.SelectedDateProperty, property.CreateBinding());
     return c;
 }
 /// <summary>
 /// Creates a content control.
 /// </summary>
 /// <param name="property">The property.</param>
 /// <returns>
 /// A <see cref="ContentControl" />.
 /// </returns>
 protected virtual FrameworkElement CreateContentControl(PropertyItem property)
 {
     var b = new ContentControl
     {
         HorizontalAlignment = HorizontalAlignment.Stretch,
         VerticalAlignment = VerticalAlignment.Center,
         Margin = new Thickness(4),
         Focusable = false,
         HorizontalContentAlignment = HorizontalAlignment.Stretch
     };
     b.SetBinding(ContentControl.ContentProperty, property.CreateBinding());
     return b;
 }
 /// <summary>
 /// Creates a comment control.
 /// </summary>
 /// <param name="property">The property.</param>
 /// <returns>
 /// The control.
 /// </returns>
 protected virtual FrameworkElement CreateCommentControl(PropertyItem property)
 {
     var tb = new TextBlock
                  {
                      VerticalAlignment = VerticalAlignment.Center,
                      Margin = new Thickness(4),
                      Focusable = false,
                      TextWrapping = TextWrapping.Wrap
                  };
     ScrollViewer.SetHorizontalScrollBarVisibility(tb, ScrollBarVisibility.Hidden);
     ScrollViewer.SetVerticalScrollBarVisibility(tb, ScrollBarVisibility.Hidden);
     tb.SetBinding(TextBlock.TextProperty, property.CreateBinding());
     return tb;
 }
        /// <summary>
        /// Creates the spin control.
        /// </summary>
        /// <param name="property">The property.</param>
        /// <returns>
        /// The control.
        /// </returns>
        protected virtual FrameworkElement CreateSpinControl(PropertyItem property)
        {
            var tb = new TextBoxEx
                {
                    IsReadOnly = property.IsReadOnly,
                    BorderThickness = new Thickness(0),
                    HorizontalContentAlignment = ConvertHorizontalAlignment(property.HorizontalAlignment),
                    VerticalContentAlignment = VerticalAlignment.Center
                };
            tb.SetBinding(TextBox.TextProperty, property.CreateBinding());
            var c = new SpinControl
                {
                    Maximum = property.SpinMaximum,
                    Minimum = property.SpinMinimum,
                    SmallChange = property.SpinSmallChange,
                    LargeChange = property.SpinLargeChange,
                    Content = tb
                };

            // Note: Do not apply the converter to the SpinControl
            c.SetBinding(SpinControl.ValueProperty, property.CreateBinding(UpdateSourceTrigger.Default, false));
            return c;
        }
        /// <summary>
        /// Creates the enum control.
        /// </summary>
        /// <param name="property">
        /// The property.
        /// </param>
        /// <param name="options">
        /// The options.
        /// </param>
        /// <returns>
        /// The control.
        /// </returns>
        protected FrameworkElement CreateEnumControl(PropertyItem property, PropertyControlFactoryOptions options)
        {
            var isRadioButton = true;
            var enumType = TypeHelper.GetEnumType(property.Descriptor.PropertyType);
            var values = Enum.GetValues(enumType);
            if (values.Length > options.EnumAsRadioButtonsLimit && !property.UseRadioButtons)
            {
                isRadioButton = false;
            }

            if (isRadioButton)
            {
                var c = new RadioButtonList { EnumType = property.Descriptor.PropertyType };
                c.SetBinding(RadioButtonList.ValueProperty, property.CreateBinding());
                return c;
            }
            else
            {
                var c = new ComboBox { ItemsSource = Enum.GetValues(enumType) };
                c.SetBinding(Selector.SelectedValueProperty, property.CreateBinding());
                return c;
            }
        }
        /// <summary>
        /// Creates a sequence of checkboxes.
        /// </summary>
        /// <param name="property">The property.</param>
        /// <returns>
        /// A FrameworkElement.
        /// </returns>
        protected virtual FrameworkElement CreateCheckableItems(PropertyItem property)
        {
            var lb = new ItemsControl();
            var rectangleFactory = new FrameworkElementFactory(typeof(CheckBox));
            rectangleFactory.SetBinding(ToggleButton.IsCheckedProperty, new Binding(property.CheckableItemsIsCheckedPropertyName));
            rectangleFactory.SetBinding(ContentControl.ContentProperty, new Binding(property.CheckableItemsContentPropertyName));

            lb.ItemTemplate = new DataTemplate { VisualTree = rectangleFactory };
            lb.SetBinding(ItemsControl.ItemsSourceProperty, property.CreateBinding());
            lb.Margin = new Thickness(0, 6, 0, 6);

            return lb;
        }
 /// <summary>
 /// Creates the color control.
 /// </summary>
 /// <param name="property">The property.</param>
 /// <returns>
 /// The control.
 /// </returns>
 protected virtual FrameworkElement CreateColorControl(PropertyItem property)
 {
     var c = new ColorPicker();
     c.SetBinding(ColorPicker.SelectedColorProperty, property.CreateBinding());
     return c;
 }
        /// <summary>
        /// Creates the file path control.
        /// </summary>
        /// <param name="property">
        /// The property.
        /// </param>
        /// <returns>
        /// The control.
        /// </returns>
        protected FrameworkElement CreateFilePathControl(PropertyItem property)
        {
            var c = new FilePicker
                {
                    Filter = property.FilePathFilter,
                    DefaultExtension = property.FilePathDefaultExtension,
                    UseOpenDialog = property.IsFileOpenDialog,
                    FileDialogService = this.FileDialogService
                };
            if (property.RelativePathDescriptor != null)
            {
                c.SetBinding(FilePicker.BasePathProperty, new Binding(property.RelativePathDescriptor.Name));
            }

            if (property.FilterDescriptor != null)
            {
                c.SetBinding(FilePicker.FilterProperty, new Binding(property.FilterDescriptor.Name));
            }

            c.SetBinding(FilePicker.FilePathProperty, property.CreateBinding());
            return c;
        }
 /// <summary>
 /// Creates the bool control.
 /// </summary>
 /// <param name="property">
 /// The property.
 /// </param>
 /// <returns>
 /// The control.
 /// </returns>
 protected FrameworkElement CreateBoolControl(PropertyItem property)
 {
     var c = new CheckBox
         {
            VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Left
         };
     c.SetBinding(ToggleButton.IsCheckedProperty, property.CreateBinding());
     return c;
 }
 /// <summary>
 /// Creates the directory path control.
 /// </summary>
 /// <param name="property">
 /// The property.
 /// </param>
 /// <returns>
 /// The control.
 /// </returns>
 protected FrameworkElement CreateDirectoryPathControl(PropertyItem property)
 {
     var c = new DirectoryPicker { FolderBrowserDialogService = this.FolderBrowserDialogService };
     c.SetBinding(DirectoryPicker.DirectoryProperty, property.CreateBinding());
     return c;
 }
        /// <summary>
        /// Creates the font family control.
        /// </summary>
        /// <param name="property">The property.</param>
        /// <returns>
        /// The control.
        /// </returns>
        protected virtual FrameworkElement CreateFontFamilyControl(PropertyItem property)
        {
            var c = new ComboBox { ItemsSource = GetFontFamilies() };

            if (property.PreviewFonts)
            {
                var dt = new DataTemplate { DataType = typeof(ComboBox) };
                var factory = new FrameworkElementFactory(typeof(TextBlock));
                factory.SetValue(TextBlock.FontSizeProperty, property.FontSize);
                factory.SetValue(TextBlock.FontWeightProperty, FontWeight.FromOpenTypeWeight(property.FontWeight));
                factory.SetBinding(TextBlock.TextProperty, new Binding());
                factory.SetBinding(TextBlock.FontFamilyProperty, new Binding { Converter = FontFamilyConverter });
                dt.VisualTree = factory;
                c.ItemTemplate = dt;
            }

            var binding = property.CreateBinding();
            if (property.ActualPropertyType == typeof(string))
            {
                binding.Converter = FontFamilyConverter;
            }

            c.SetBinding(Selector.SelectedValueProperty, binding);
            return c;
        }
        /// <summary>
        /// Creates the grid control.
        /// </summary>
        /// <param name="property">The property.</param>
        /// <returns>
        /// The control.
        /// </returns>
        protected virtual FrameworkElement CreateGridControl(PropertyItem property)
        {
            var c = new DataGrid
            {
                CanDelete = property.ListCanRemove,
                CanInsert = property.ListCanAdd,
                InputDirection = property.InputDirection,
                EasyInsert = property.EasyInsert,
                AutoGenerateColumns = property.Columns.Count == 0
            };

            var glc = new GridLengthConverter();
            foreach (var ca in property.Columns.OrderBy(cd => cd.ColumnIndex))
            {
                var cd = new ColumnDefinition
                    {
                        PropertyName = ca.PropertyName,
                        Header = ca.Header,
                        FormatString = ca.FormatString,
                        Width = (GridLength)(glc.ConvertFromInvariantString(ca.Width) ?? GridLength.Auto),
                        IsReadOnly = ca.IsReadOnly
                    };

                if (ca.PropertyName == string.Empty && property.ListItemItemsSource != null)
                {
                    cd.ItemsSource = property.ListItemItemsSource;
                }

                switch (ca.Alignment.ToString(CultureInfo.InvariantCulture).ToUpper())
                {
                    case "L":
                        cd.HorizontalAlignment = HorizontalAlignment.Left;
                        break;
                    case "R":
                        cd.HorizontalAlignment = HorizontalAlignment.Right;
                        break;
                    default:
                        cd.HorizontalAlignment = HorizontalAlignment.Center;
                        break;
                }

                c.ColumnDefinitions.Add(cd);
            }

            c.SetBinding(DataGrid.ItemsSourceProperty, property.CreateBinding());
            return c;
        }
 /// <summary>
 /// Creates the HTML control.
 /// </summary>
 /// <param name="property">The property.</param>
 /// <returns>
 /// The control.
 /// </returns>
 protected virtual FrameworkElement CreateHtmlControl(PropertyItem property)
 {
     var c = new WebBrowser();
     c.SetBinding(WebBrowserBehavior.NavigateToStringProperty, property.CreateBinding());
     return c;
 }
        /// <summary>
        /// Creates the select control.
        /// </summary>
        /// <param name="property">The property.</param>
        /// <param name="options">The options.</param>
        /// <returns>
        /// The control.
        /// </returns>
        protected virtual FrameworkElement CreateEnumControl(
            PropertyItem property, PropertyControlFactoryOptions options)
        {
            var enumType = TypeHelper.GetEnumType(property.Descriptor.PropertyType);
            var values = Enum.GetValues(enumType);
            var style = property.SelectorStyle;
            if (style == DataAnnotations.SelectorStyle.Auto)
            {
                style = values.Length > options.EnumAsRadioButtonsLimit
                            ? DataAnnotations.SelectorStyle.ComboBox
                            : DataAnnotations.SelectorStyle.RadioButtons;
            }

            switch (style)
            {
                case DataAnnotations.SelectorStyle.RadioButtons:
                    {
                        var c = new RadioButtonList { EnumType = property.Descriptor.PropertyType };
                        c.SetBinding(RadioButtonList.ValueProperty, property.CreateBinding());
                        return c;
                    }

                case DataAnnotations.SelectorStyle.ComboBox:
                    {
                        var c = new ComboBox { ItemsSource = Enum.GetValues(enumType) };
                        c.SetBinding(Selector.SelectedValueProperty, property.CreateBinding());
                        return c;
                    }

                case DataAnnotations.SelectorStyle.ListBox:
                    {
                        var c = new ListBox { ItemsSource = Enum.GetValues(enumType) };
                        c.SetBinding(Selector.SelectedValueProperty, property.CreateBinding());
                        return c;
                    }

                default:
                    return null;
            }
        }
 /// <summary>
 /// Creates the spin control.
 /// </summary>
 /// <param name="property">
 /// The property.
 /// </param>
 /// <returns>
 /// The control.
 /// </returns>
 protected FrameworkElement CreateSpinControl(PropertyItem property)
 {
     var tb = new TextBox
         {
            BorderThickness = new Thickness(0), HorizontalContentAlignment = HorizontalAlignment.Right
         };
     tb.SetBinding(TextBox.TextProperty, property.CreateBinding());
     var c = new SpinControl
         {
             Maximum = property.SpinMaximum,
             Minimum = property.SpinMinimum,
             SmallChange = property.SpinSmallChange,
             LargeChange = property.SpinLargeChange,
             Content = tb
         };
     c.SetBinding(SpinControl.ValueProperty, property.CreateBinding());
     return c;
 }
        /// <summary>
        /// Creates the file path control.
        /// </summary>
        /// <param name="property">The property.</param>
        /// <returns>
        /// The control.
        /// </returns>
        protected virtual FrameworkElement CreateFilePathControl(PropertyItem property)
        {
            var c = new FilePicker
                {
                    Filter = property.FilePathFilter,
                    DefaultExtension = property.FilePathDefaultExtension,
                    UseOpenDialog = property.IsFileOpenDialog,
                    FileDialogService = this.FileDialogService
                };
            if (property.RelativePathDescriptor != null)
            {
                c.SetBinding(FilePicker.BasePathProperty, new Binding(property.RelativePathDescriptor.Name));
            }

            if (property.FilterDescriptor != null)
            {
                c.SetBinding(FilePicker.FilterProperty, new Binding(property.FilterDescriptor.Name));
            }

            if (property.DefaultExtensionDescriptor != null)
            {
                c.SetBinding(FilePicker.DefaultExtensionProperty, new Binding(property.DefaultExtensionDescriptor.Name));
            }

            var trigger = property.AutoUpdateText ? UpdateSourceTrigger.PropertyChanged : UpdateSourceTrigger.Default;
            c.SetBinding(FilePicker.FilePathProperty, property.CreateBinding(trigger));
            return c;
        }
        /// <summary>
        /// Creates the grid control.
        /// </summary>
        /// <param name="property">The property.</param>
        /// <returns>
        /// The control.
        /// </returns>
        protected virtual FrameworkElement CreateGridControl(PropertyItem property)
        {
            var c = new DataGrid
            {
                CanDelete = property.ListCanRemove,
                CanInsert = property.ListCanAdd,
                InputDirection = property.InputDirection,
                EasyInsert = property.EasyInsert,
                AutoGenerateColumns = property.Columns.Count == 0
            };

            foreach (var cd in property.Columns)
            {
                if (cd.PropertyName == string.Empty && property.ListItemItemsSource != null)
                {
                    cd.ItemsSource = property.ListItemItemsSource;
                }

                c.ColumnDefinitions.Add(cd);
            }

            c.SetBinding(DataGrid.ItemsSourceProperty, property.CreateBinding());
            return c;
        }