/// <summary> /// Generates a list of objects to be used in the DefaultItems collection. /// </summary> /// <param name="defaultItems">The collection that should be updated.</param> protected override void GenerateDefaultItems(SlottedItemCollection defaultItems) { base.GenerateDefaultItems(defaultItems); DecimalPartGroup decimalGroup = new DecimalPartGroup(); decimalGroup.SetBinding(DecimalPartGroup.IsReadOnlyProperty, new Binding("IsReadOnly") { Source = this }); decimalGroup.SetBinding(DecimalTextBox.StringFormatProperty, new Binding("StringFormat") { Source = this }); decimalGroup.SetBinding(DecimalPartGroup.MaximumProperty, new Binding("Maximum") { Source = this, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged }); decimalGroup.SetBinding(DecimalPartGroup.MinimumProperty, new Binding("Minimum") { Source = this, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged }); SyncBinding.CreateBinding(this, DecimalTextBox.ValueProperty, decimalGroup, DecimalPartGroup.ValueProperty, UpdateSourceTrigger.PropertyChanged); defaultItems.Add(decimalGroup); }
/// <summary> /// Handle the minimum value changing. /// </summary> /// <param name="sender">The decimal part whose minimum value changed.</param> /// <param name="eventArgs">The event arguments.</param> private static void OnMinimumChanged(DependencyObject sender, DependencyPropertyChangedEventArgs eventArgs) { // Clip the value at the minimum. DecimalPartGroup part = sender as DecimalPartGroup; if (part.Value < part.Minimum) { part.Value = part.Minimum; } }
/// <summary> /// Handle the maximum value changing. /// </summary> /// <param name="sender">The decimal part whose maximum value changed.</param> /// <param name="eventArgs">The event arguments.</param> private static void OnMaximumChanged(DependencyObject sender, DependencyPropertyChangedEventArgs eventArgs) { // Clip the value at the maxmum. DecimalPartGroup decimalPartGroup = sender as DecimalPartGroup; if (decimalPartGroup.Value > decimalPartGroup.Maximum) { decimalPartGroup.Value = decimalPartGroup.Maximum; } }
/// <summary> /// Generates a list of objects to be used in the DefaultItems collection. /// </summary> /// <param name="defaultItems">The collection that should be updated.</param> protected override void GenerateDefaultItems(SlottedItemCollection defaultItems) { // Allow the base class to provide most of the default items. base.GenerateDefaultItems(defaultItems); // This control will create a special group of parts for a decimal implementation of a percent value. DecimalPartGroup decimalPartGroup = new DecimalPartGroup(); decimalPartGroup.SetBinding(DecimalPartGroup.StringFormatProperty, new Binding("Format") { Source = this }); decimalPartGroup.SetBinding(DecimalPartGroup.IsReadOnlyProperty, new Binding("IsReadOnly") { Source = this }); decimalPartGroup.SetBinding( DecimalPartGroup.MaximumProperty, new Binding("Maximum") { Source = this, Converter = new PercentageConverter(), UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged }); decimalPartGroup.SetBinding( DecimalPartGroup.MinimumProperty, new Binding("Minimum") { Source = this, Converter = new PercentageConverter(), UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged }); decimalPartGroup.SetBinding( DecimalPartGroup.StepProperty, new Binding("Step") { Source = this, Converter = new PercentageConverter(), UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged }); SyncBinding.CreateBinding( this, DecimalTextBox.ValueProperty, decimalPartGroup, DecimalPartGroup.ValueProperty, UpdateSourceTrigger.PropertyChanged, new PercentageConverter()); defaultItems.Add(decimalPartGroup); defaultItems.Add(new TextBlockPartGroup() { Text = "%" }); }