Example #1
0
        /// <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 new minimum.
            DecimalPart part = sender as DecimalPart;

            if (part.Value < part.Minimum)
            {
                part.Value = part.Minimum;
            }
        }
        /// <summary>
        /// Generate default parts.
        /// </summary>
        /// <param name="defaultItems"></param>
        protected override void GenerateDefaultItems(ActiproSoftware.Windows.Controls.Editors.Primitives.SlottedItemCollection defaultItems)
        {
            // Allow the base class to set its defaults.
            base.GenerateDefaultItems(defaultItems);

            // This group will add a new set of defaults for the decimal part of the edit box.
            DecimalPart decimalPart = new DecimalPart();

            decimalPart.SetBinding(DecimalPart.StringFormatProperty, new Binding("StringFormat")
            {
                Source = this
            });
            decimalPart.SetBinding(DecimalPart.IsReadOnlyProperty, new Binding("IsReadOnly")
            {
                Source = this
            });
            decimalPart.SetBinding(DecimalPart.MaximumProperty, new Binding("Maximum")
            {
                Source = this
            });
            decimalPart.SetBinding(DecimalPart.MinimumProperty, new Binding("Minimum")
            {
                Source = this
            });
            decimalPart.SetBinding(DecimalPart.StepProperty, new Binding("Step")
            {
                Source = this, Mode = BindingMode.TwoWay, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
            });
            decimalPart.SetBinding(DecimalPart.ValueProperty, new Binding("Value")
            {
                Source = this, Mode = BindingMode.TwoWay, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
            });
            SyncBinding.CreateBinding(this, DecimalPartGroup.InitialValueProperty, decimalPart, DecimalPart.InitialValueProperty);
            SyncBinding.CreateBinding(
                this,
                DecimalPartGroup.PartValueCommitTriggersProperty,
                decimalPart,
                DecimalPart.PartValueCommitTriggersProperty,
                UpdateSourceTrigger.Default);
            decimalPart.IsFocusMovedOnTerminalMatches = true;
            decimalPart.IsTabStop = true;
            defaultItems.Add(decimalPart);
        }