コード例 #1
0
        /// <summary>
        /// Handle the Value of MarketValueBox changing. Change the value of Text to match.
        /// </summary>
        /// <param name="sender">The MarketValueBox.</param>
        /// <param name="eventArgs">The event arguments.</param>
        static private void OnValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs eventArgs)
        {
            // Display the value formatted for the local currency using the Text property of this control.
            MarketValueBox marketValueBox = sender as MarketValueBox;

            marketValueBox.SetValue(TextBox.TextProperty, String.Format("{0:#,##0.00}", marketValueBox.Value));
            marketValueBox.RaiseEvent(new RoutedEventArgs(MarketValueBox.ValueChangedEvent));
        }
コード例 #2
0
        /// <summary>
        /// Create a new MarketValueBox.
        /// </summary>
        public MarketValueBox()
        {
            // Initialize the object.
            this.originalBorderThickness = default(Thickness);
            this.originalBackground      = default(Brush);

            // One problem with the event driven architecture is that it's difficult to initialize the controls with the default value.  There are no events
            // fired because setting the control to it's default value doesn't generate a 'Property Changed' event.  This code here will force the defalt value
            // into the control in the proper format.
            MarketValueBox.OnValueChanged(this, new DependencyPropertyChangedEventArgs(MarketValueBox.ValueProperty, 0.0M, 0.0M));
        }
コード例 #3
0
        /// <summary>
        /// Handle the Value of MarketValueBox changing. Change the value of Text to match.
        /// </summary>
        /// <param name="sender">The MarketValueBox.</param>
        /// <param name="eventArgs">The event arguments.</param>
        static private void OnIsReadOnlyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs eventArgs)
        {
            // Remove the border of the control when in the read-only mode and restore it when editing is allowed.
            MarketValueBox marketValueBox = sender as MarketValueBox;

            if (Convert.ToBoolean(eventArgs.NewValue))
            {
                marketValueBox.originalBorderThickness = marketValueBox.BorderThickness;
                marketValueBox.BorderThickness         = new Thickness(0);
                marketValueBox.Background = Brushes.Transparent;
            }
            else
            {
                marketValueBox.Background      = marketValueBox.originalBackground;
                marketValueBox.BorderThickness = marketValueBox.originalBorderThickness;
            }
        }