// (c) Copyright Microsoft Corporation. // This source is subject to the Microsoft Public License (Ms-PL). // Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details. // All other rights reserved. using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Windows; using System.Windows.Controls; using System.Windows.Data; namespace System.Windows.Controls.DataVisualization.Charting { /// /// A label used to display data in an axis. /// public class AxisLabel : Control { #region public string StringFormat /// /// Gets or sets the text string format. /// public string StringFormat { get { return GetValue(StringFormatProperty) as string; } set { SetValue(StringFormatProperty, value); } } /// /// Identifies the StringFormat dependency property. /// public static readonly DependencyProperty StringFormatProperty = DependencyProperty.Register( "StringFormat", typeof(string), typeof(AxisLabel), new PropertyMetadata(null, OnStringFormatPropertyChanged)); /// /// StringFormatProperty property changed handler. /// /// AxisLabel that changed its StringFormat. /// Event arguments. private static void OnStringFormatPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { AxisLabel source = (AxisLabel)d; string newValue = (string)e.NewValue; source.OnStringFormatPropertyChanged(newValue); } /// /// StringFormatProperty property changed handler. /// /// New value. protected virtual void OnStringFormatPropertyChanged(string newValue) { UpdateFormattedContent(); } #endregion public string StringFormat #region public string FormattedContent /// /// Gets the formatted content property. /// public string FormattedContent { get { return GetValue(FormattedContentProperty) as string; } protected set { SetValue(FormattedContentProperty, value); } } /// /// Identifies the FormattedContent dependency property. /// public static readonly DependencyProperty FormattedContentProperty = DependencyProperty.Register( "FormattedContent", typeof(string), typeof(AxisLabel), new PropertyMetadata(null)); #endregion public string FormattedContent #if !SILVERLIGHT /// /// Initializes the static members of the AxisLabel class. /// [SuppressMessage("Microsoft.Performance", "CA1810:InitializeReferenceTypeStaticFieldsInline", Justification = "Dependency properties are initialized in-line.")] static AxisLabel() { DefaultStyleKeyProperty.OverrideMetadata(typeof(AxisLabel), new FrameworkPropertyMetadata(typeof(AxisLabel))); } #endif /// /// Instantiates a new instance of the AxisLabel class. /// public AxisLabel() { #if SILVERLIGHT this.DefaultStyleKey = typeof(AxisLabel); #endif this.SetBinding(FormattedContentProperty, new Binding { Converter = new StringFormatConverter(), ConverterParameter = StringFormat ?? "{0}" }); } /// /// Updates the formatted text. /// protected virtual void UpdateFormattedContent() { this.SetBinding(FormattedContentProperty, new Binding { Converter = new StringFormatConverter(), ConverterParameter = StringFormat ?? "{0}" }); } } }