/// <summary> /// Creates the font preview. /// </summary> /// <param name="property">The property.</param> /// <returns> /// The control. /// </returns> protected virtual FrameworkElement CreateFontPreview(PropertyItem property) { var c = new TextBoxEx { Background = Brushes.Transparent, BorderBrush = null, AcceptsReturn = true, IsReadOnly = property.IsReadOnly, TextWrapping = TextWrapping.Wrap, FontWeight = FontWeight.FromOpenTypeWeight(property.FontWeight), FontSize = property.FontSize }; TextOptions.SetTextFormattingMode(c, TextFormattingMode.Display); TextOptions.SetTextRenderingMode(c, TextRenderingMode.ClearType); c.SetBinding(TextBox.TextProperty, new Binding(property.Descriptor.Name) { Mode = BindingMode.OneWay }); if (property.FontFamilyPropertyDescriptor != null) { c.SetBinding(Control.FontFamilyProperty, new Binding(property.FontFamilyPropertyDescriptor.Name)); } return(c); }
/// <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 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 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 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 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 font preview. /// </summary> /// <param name="property">The property.</param> /// <returns> /// The control. /// </returns> protected virtual FrameworkElement CreateFontPreview(PropertyItem property) { var c = new TextBoxEx { Background = Brushes.Transparent, BorderBrush = null, AcceptsReturn = true, IsReadOnly = property.IsReadOnly, TextWrapping = TextWrapping.Wrap, FontWeight = FontWeight.FromOpenTypeWeight(property.FontWeight), FontSize = property.FontSize }; TextOptions.SetTextFormattingMode(c, TextFormattingMode.Display); TextOptions.SetTextRenderingMode(c, TextRenderingMode.ClearType); c.SetBinding(TextBox.TextProperty, new Binding(property.Descriptor.Name) { Mode = BindingMode.OneWay }); if (property.FontFamilyPropertyDescriptor != null) { c.SetBinding(Control.FontFamilyProperty, new Binding(property.FontFamilyPropertyDescriptor.Name)); } 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; }