using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; namespace Tango.Visuals { /// /// Interaction logic for TicksAxis.xaml /// public partial class YAxisTicks : UserControl { #region Constructors /// /// Initializes a new instance of the class. /// public YAxisTicks() { InitializeComponent(); this.FocusVisualStyle = null; this.Focusable = false; this.Loaded += TicksAxis_Loaded; } #endregion #region Event Handlers /// /// Handles the Loaded event of the TicksAxis control. /// /// The source of the event. /// The instance containing the event data. private void TicksAxis_Loaded(object sender, RoutedEventArgs e) { DrawTicks(); } #endregion #region Properties /// /// Gets or sets the ticks. /// public int Ticks { get { return (int)GetValue(TicksProperty); } set { SetValue(TicksProperty, value); } } public static readonly DependencyProperty TicksProperty = DependencyProperty.Register("Ticks", typeof(int), typeof(YAxisTicks), new PropertyMetadata(11, (d, e) => (d as YAxisTicks).DrawTicks())); /// /// Gets or sets the tick template. /// public DataTemplate TickTemplate { get { return (DataTemplate)GetValue(TickTemplateProperty); } set { SetValue(TickTemplateProperty, value); } } public static readonly DependencyProperty TickTemplateProperty = DependencyProperty.Register("TickTemplate", typeof(DataTemplate), typeof(YAxisTicks), new PropertyMetadata(null, (d, e) => (d as YAxisTicks).DrawTicks())); /// /// Gets or sets the big tick interval. /// public int? BigTickInterval { get { return (int?)GetValue(BigTickIntervalProperty); } set { SetValue(BigTickIntervalProperty, value); } } public static readonly DependencyProperty BigTickIntervalProperty = DependencyProperty.Register("BigTickInterval", typeof(int?), typeof(YAxisTicks), new PropertyMetadata(null, (d, e) => (d as YAxisTicks).DrawTicks())); /// /// Gets or sets the big tick template. /// public DataTemplate BigTickTemplate { get { return (DataTemplate)GetValue(BigTickTemplateProperty); } set { SetValue(BigTickTemplateProperty, value); } } public static readonly DependencyProperty BigTickTemplateProperty = DependencyProperty.Register("BigTickTemplate", typeof(DataTemplate), typeof(YAxisTicks), new PropertyMetadata(null)); #endregion #region Methods /// /// Draws the ticks. /// private void DrawTicks() { grid.Children.Clear(); grid.RowDefinitions.Clear(); for (int i = 0; i < Ticks; i++) { if (i == Ticks - 1) { ContentControl tick = null; if (BigTickInterval != null && BigTickTemplate != null) { tick = AddBigTick(i, i); } else { tick = AddTick(i, i); } tick.VerticalAlignment = System.Windows.VerticalAlignment.Bottom; grid.Children.Add(tick); } else { ContentControl tick = null; RowDefinition row = new RowDefinition(); row.Height = new GridLength(1, GridUnitType.Star); grid.RowDefinitions.Add(row); if (BigTickInterval != null && (double)i % (double)BigTickInterval == 0 && BigTickTemplate != null) { tick = AddBigTick(i, i); } else { tick = AddTick(i, i); } grid.Children.Add(tick); } } } /// /// Adds the tick. /// /// The value. /// The index. /// private ContentControl AddTick(double value, int index) { ContentControl tick = new ContentControl(); tick.Focusable = false; tick.VerticalAlignment = System.Windows.VerticalAlignment.Top; tick.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch; Grid.SetRow(tick, index); if (TickTemplate != null) { tick.ContentTemplate = TickTemplate; } return tick; } /// /// Adds big tick. /// /// The value. /// The index. /// private ContentControl AddBigTick(double value, int index) { ContentControl tick = new ContentControl(); tick.Focusable = false; tick.VerticalAlignment = System.Windows.VerticalAlignment.Top; tick.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch; Grid.SetRow(tick, index); if (BigTickTemplate != null) { tick.ContentTemplate = BigTickTemplate; } return tick; } #endregion } }