Beispiel #1
0
        /// <summary>
        /// Handles a change to the format of the data.
        /// </summary>
        /// <param name="dependencyObject">The dependency object that has been changed.</param>
        /// <param name="dependencyPropertyChangedEventArgs">The event arguments describing the change to the property.</param>
        public static void OnFormatChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs)
        {
            // Reformat the text in the control when the format changes.
            ValueBlock valueBlock = dependencyObject as ValueBlock;
            String     format     = dependencyPropertyChangedEventArgs.NewValue as String;
            Object     value      = valueBlock.GetValue(ValueBlock.ContentProperty);

            valueBlock.SetValue(TextBlock.TextProperty, String.Format(format, value));
        }
Beispiel #2
0
        /// <summary>
        /// Handles a change to the value of this control.
        /// </summary>
        /// <param name="dependencyObject">The dependency object that has been changed.</param>
        /// <param name="dependencyPropertyChangedEventArgs">The event arguments describing the change to the property.</param>
        public static void OnContentChanged(DependencyObject dependencyObject,
                                            DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs)
        {
            // Display the value using the Format property in the Text property of the base class.
            ValueBlock valueBlock = dependencyObject as ValueBlock;
            String     format     = valueBlock.GetValue(ValueBlock.FormatProperty) as String;
            Object     value      = dependencyPropertyChangedEventArgs.NewValue;

            valueBlock.SetValue(ValueBlock.TextProperty, String.Format(format, value));

            // Recycling this control can lead to false Up/Down indications because the old value is no longer relavent to the new
            // value.  When the data context of the control has changed, the next property update will not attempt to trigger an
            // Up/Down event.
            if (valueBlock.ignoreChange)
            {
                valueBlock.ignoreChange = false;
            }
            else
            {
                // This provides feedback indicating whether the control has increased or decreased in value.
                if (dependencyPropertyChangedEventArgs.NewValue is IComparable &&
                    dependencyPropertyChangedEventArgs.OldValue is IComparable)
                {
                    IComparable iComparable = dependencyPropertyChangedEventArgs.NewValue as IComparable;
                    switch (iComparable.CompareTo(dependencyPropertyChangedEventArgs.OldValue))
                    {
                    case 1:

                        // Indicate that the value has increased.
                        valueBlock.SetValue(ValueBlock.IsUpProperty, true);
                        valueBlock.SetValue(ValueBlock.IsDownProperty, false);

                        // Raise an event that indicates the value has increased.
                        valueBlock.RaiseEvent(new RoutedEventArgs(ValueBlock.IncreaseEvent));

                        break;

                    case -1:

                        // Indicate that the value has decreased.
                        valueBlock.SetValue(ValueBlock.IsUpProperty, false);
                        valueBlock.SetValue(ValueBlock.IsDownProperty, true);

                        // Raise an event that indicates the value has decreased.
                        valueBlock.RaiseEvent(new RoutedEventArgs(ValueBlock.DecreaseEvent));

                        break;
                    }
                }
            }
        }