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.Components
{
///
/// Interaction logic for TicksAxis.xaml
///
internal partial class XAxisTicks : UserControl
{
#region Constructors
///
/// Initializes a new instance of the class.
///
public XAxisTicks()
{
InitializeComponent();
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.
///
///
/// 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(XAxisTicks), new PropertyMetadata(11));
///
/// Gets or sets the tick template.
///
///
/// 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(XAxisTicks), new PropertyMetadata(null));
#endregion
#region Methods
///
/// Draws the ticks.
///
private void DrawTicks()
{
grid.Children.Clear();
grid.ColumnDefinitions.Clear();
for (int i = 0; i < Ticks; i++)
{
if (i == Ticks - 1)
{
var rec = AddTick(i, i);
rec.HorizontalAlignment = System.Windows.HorizontalAlignment.Right;
grid.Children.Add(rec);
}
else
{
ColumnDefinition column = new ColumnDefinition();
column.Width = new GridLength(1, GridUnitType.Star);
grid.ColumnDefinitions.Add(column);
var rec = AddTick(i, i);
grid.Children.Add(rec);
}
}
}
///
/// Adds the tick.
///
/// The value.
/// The index.
///
private ContentControl AddTick(double value, int index)
{
ContentControl tick = new ContentControl();
tick.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
tick.VerticalAlignment = System.Windows.VerticalAlignment.Stretch;
Grid.SetColumn(tick, index);
if (TickTemplate != null)
{
tick.ContentTemplate = TickTemplate;
}
return tick;
}
#endregion
}
}