diff options
| author | Roy <roy.mail.net@gmail.com> | 2018-02-09 13:41:58 +0200 |
|---|---|---|
| committer | Roy <roy.mail.net@gmail.com> | 2018-02-09 13:41:58 +0200 |
| commit | c8c9606e545f49aae3d9f0524775436adbdf27e9 (patch) | |
| tree | 83d9fe870f652058af96f32b7159186f5b80f491 /Software/Visual_Studio/Tango.Visuals/Components | |
| parent | bfcefc0cf95f3b8d5243908753129c79bad8dc8b (diff) | |
| download | Tango-c8c9606e545f49aae3d9f0524775436adbdf27e9.tar.gz Tango-c8c9606e545f49aae3d9f0524775436adbdf27e9.zip | |
Added my Controls Library !
Implemented Tech VU Item.
Diffstat (limited to 'Software/Visual_Studio/Tango.Visuals/Components')
13 files changed, 866 insertions, 0 deletions
diff --git a/Software/Visual_Studio/Tango.Visuals/Components/Arc.cs b/Software/Visual_Studio/Tango.Visuals/Components/Arc.cs new file mode 100644 index 000000000..02fc3aab5 --- /dev/null +++ b/Software/Visual_Studio/Tango.Visuals/Components/Arc.cs @@ -0,0 +1,64 @@ +using System; +using System.Collections.Generic; +using System.Windows; +using System.Windows.Documents; +using System.Windows.Media; +using System.Windows.Shapes; + +namespace Tango.Visuals.Components +{ + internal class Arc : Shape + { + public double StartAngle + { + get { return (double)GetValue(StartAngleProperty); } + set { SetValue(StartAngleProperty, value); } + } + public static readonly DependencyProperty StartAngleProperty = + DependencyProperty.Register("StartAngle", typeof(double), typeof(Arc), new PropertyMetadata(0.0)); + + public double EndAngle + { + get { return (double)GetValue(EndAngleProperty); } + set { SetValue(EndAngleProperty, value); } + } + public static readonly DependencyProperty EndAngleProperty = + DependencyProperty.Register("EndAngle", typeof(double), typeof(Arc), new PropertyMetadata(90.0)); + + protected override Geometry DefiningGeometry + { + get + { + double maxWidth = RenderSize.Width; + double maxHeight = RenderSize.Height; + double maxRadius = Math.Min(maxWidth, maxHeight) / 2.0; + + PolarPoint arcStart = new PolarPoint(maxRadius, StartAngle); + PolarPoint arcFinish = new PolarPoint(maxRadius, EndAngle); + + StreamGeometry geom = new StreamGeometry(); + using (StreamGeometryContext ctx = geom.Open()) + { + ctx.BeginFigure( + new Point((maxWidth / 2.0) + arcStart.X, + (maxHeight / 2.0) - arcStart.Y), + false, + false); + ctx.ArcTo( + new Point((maxWidth / 2.0) + arcFinish.X, + (maxHeight / 2.0) - arcFinish.Y), + new Size(maxRadius, maxRadius), + 0.0, // rotationAngle + EndAngle > 180 && StartAngle < 180 && (EndAngle - StartAngle) > 180, // greater than 180 deg? + SweepDirection.Counterclockwise, + true, // isStroked + true); + } + + geom.Transform = new RotateTransform((-90 + EndAngle) + StartAngle, maxWidth / 2, maxHeight / 2); + + return geom; + } + } + } +}
\ No newline at end of file diff --git a/Software/Visual_Studio/Tango.Visuals/Components/PieAxisTicks.xaml b/Software/Visual_Studio/Tango.Visuals/Components/PieAxisTicks.xaml new file mode 100644 index 000000000..535524d32 --- /dev/null +++ b/Software/Visual_Studio/Tango.Visuals/Components/PieAxisTicks.xaml @@ -0,0 +1,41 @@ +<UserControl x:ClassModifier="internal" x:Class="Tango.Visuals.Components.PieAxisTicks" + xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + mc:Ignorable="d" + d:DesignHeight="300" d:DesignWidth="300" Background="White"> + <Grid> + <Grid RenderTransformOrigin="0.5,1"> + <Grid.RenderTransform> + <RotateTransform Angle="90"></RotateTransform> + </Grid.RenderTransform> + <Grid.ColumnDefinitions> + <ColumnDefinition Width="1*"/> + <ColumnDefinition Width="1*"/> + </Grid.ColumnDefinitions> + <Grid.RowDefinitions> + <RowDefinition Height="1*"/> + <RowDefinition Height="1*"/> + <RowDefinition Height="1*"/> + <RowDefinition Height="1*"/> + <RowDefinition Height="1*"/> + <RowDefinition Height="1*"/> + </Grid.RowDefinitions> + + <Rectangle Width="1" VerticalAlignment="Stretch" Grid.RowSpan="5" Grid.Row="1" HorizontalAlignment="Right" Stroke="Black"></Rectangle> + + <TextBlock RenderTransformOrigin="0.5,0.5" Grid.Row="0" VerticalAlignment="Top" HorizontalAlignment="Center" FontSize="22" Grid.ColumnSpan="2" Text="uCO"> + <TextBlock.RenderTransform> + <RotateTransform Angle="-90"></RotateTransform> + </TextBlock.RenderTransform> + </TextBlock> + + <Rectangle Grid.Row="0" Width="50" Height="2" VerticalAlignment="Bottom" Stroke="Black" Grid.ColumnSpan="2"></Rectangle> + <Rectangle Grid.Row="1" Width="50" Height="2" VerticalAlignment="Bottom" Stroke="Black" Grid.ColumnSpan="2"></Rectangle> + <Rectangle Grid.Row="2" Width="50" Height="2" VerticalAlignment="Bottom" Stroke="Black" Grid.ColumnSpan="2"></Rectangle> + <Rectangle Grid.Row="3" Width="50" Height="2" VerticalAlignment="Bottom" Stroke="Black" Grid.ColumnSpan="2"></Rectangle> + <Rectangle Grid.Row="4" Width="50" Height="2" VerticalAlignment="Bottom" Stroke="Black" Grid.ColumnSpan="2"></Rectangle> + </Grid> + </Grid> +</UserControl> diff --git a/Software/Visual_Studio/Tango.Visuals/Components/PieAxisTicks.xaml.cs b/Software/Visual_Studio/Tango.Visuals/Components/PieAxisTicks.xaml.cs new file mode 100644 index 000000000..5c5ca61c9 --- /dev/null +++ b/Software/Visual_Studio/Tango.Visuals/Components/PieAxisTicks.xaml.cs @@ -0,0 +1,31 @@ +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 +{ + /// <summary> + /// Interaction logic for PieAxisTicks.xaml + /// </summary> + internal partial class PieAxisTicks : UserControl + { + /// <summary> + /// Initializes a new instance of the <see cref="PieAxisTicks"/> class. + /// </summary> + public PieAxisTicks() + { + InitializeComponent(); + } + } +} diff --git a/Software/Visual_Studio/Tango.Visuals/Components/PolarPoint.cs b/Software/Visual_Studio/Tango.Visuals/Components/PolarPoint.cs new file mode 100644 index 000000000..b2063b7a1 --- /dev/null +++ b/Software/Visual_Studio/Tango.Visuals/Components/PolarPoint.cs @@ -0,0 +1,81 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.Visuals.Components +{ + internal class PolarPoint + { + /// <summary> + /// Initializes a new instance of the <see cref="PolarPoint"/> class. + /// </summary> + /// <param name="radius">The radius.</param> + /// <param name="angleDeg">Angle expressed in degrees.</param> + /// <exception cref="ArgumentException"> + /// Radius must be non-negative + /// or + /// Angle must be in range [0,360) + /// </exception> + public PolarPoint(double radius, double angleDeg) + { + if (radius < 0.0) + throw new ArgumentException("Radius must be non-negative"); + if ((angleDeg < 0) || (angleDeg >= 360.0)) + throw new ArgumentException("Angle must be in range [0,360)"); + + Radius = radius; + AngleDeg = angleDeg; + } + + /// <summary> + /// Gets or sets the Polar coordinates. + /// </summary> + /// <value> + /// The radius. + /// </value> + public double Radius { get; set; } + + /// <summary> + /// Gets or sets the angle degree. + /// </summary> + /// <value> + /// The angle deg. + /// </value> + public double AngleDeg { get; set; } + + /// <summary> + /// Cartesian X Coordinate. + /// </summary> + /// <value> + /// The x. + /// </value> + public double X + { + get { return Radius * Math.Cos(AngleDeg * Math.PI / 180.0); } + } + + /// <summary> + /// Cartesian Y Coordinate. + /// </summary> + /// <value> + /// The y. + /// </value> + public double Y + { + get { return Radius * Math.Sin(AngleDeg * Math.PI / 180.0); } + } + + /// <summary> + /// Returns a <see cref="System.String" /> that represents this instance. + /// </summary> + /// <returns> + /// A <see cref="System.String" /> that represents this instance. + /// </returns> + public override string ToString() + { + return string.Format("({0},{1})", X, Y); + } + } +} diff --git a/Software/Visual_Studio/Tango.Visuals/Components/VULed.cs b/Software/Visual_Studio/Tango.Visuals/Components/VULed.cs new file mode 100644 index 000000000..609d2ce26 --- /dev/null +++ b/Software/Visual_Studio/Tango.Visuals/Components/VULed.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Media; + +namespace Tango.Visuals.Components +{ + internal class VULed : DependencyObject + { + public bool On + { + get { return (bool)GetValue(OnProperty); } + set { SetValue(OnProperty, value); } + } + public static readonly DependencyProperty OnProperty = + DependencyProperty.Register("On", typeof(bool), typeof(VULed), new PropertyMetadata(false)); + + public Brush Brush + { + get { return (Brush)GetValue(BrushProperty); } + set { SetValue(BrushProperty, value); } + } + public static readonly DependencyProperty BrushProperty = + DependencyProperty.Register("Brush", typeof(Brush), typeof(VULed), new PropertyMetadata(Brushes.Red)); + } +} diff --git a/Software/Visual_Studio/Tango.Visuals/Components/XAxisDoubles.xaml b/Software/Visual_Studio/Tango.Visuals/Components/XAxisDoubles.xaml new file mode 100644 index 000000000..5761491d7 --- /dev/null +++ b/Software/Visual_Studio/Tango.Visuals/Components/XAxisDoubles.xaml @@ -0,0 +1,12 @@ +<UserControl x:ClassModifier="internal" x:Class="Tango.Visuals.Components.XAxisDoubles" + xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:local="clr-namespace:Tango.Visuals.Components" + mc:Ignorable="d" + d:DesignHeight="40" d:DesignWidth="300"> + <Grid x:Name="grid"> + + </Grid> +</UserControl> diff --git a/Software/Visual_Studio/Tango.Visuals/Components/XAxisDoubles.xaml.cs b/Software/Visual_Studio/Tango.Visuals/Components/XAxisDoubles.xaml.cs new file mode 100644 index 000000000..de1d1c9b7 --- /dev/null +++ b/Software/Visual_Studio/Tango.Visuals/Components/XAxisDoubles.xaml.cs @@ -0,0 +1,142 @@ +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 +{ + /// <summary> + /// Interaction logic for XAxisDoubles.xaml + /// </summary> + internal partial class XAxisDoubles : UserControl + { + /// <summary> + /// Initializes a new instance of the <see cref="XAxisDoubles"/> class. + /// </summary> + public XAxisDoubles() + { + InitializeComponent(); + this.Loaded += XAxisDoubles_Loaded; + } + + /// <summary> + /// Handles the Loaded event of the XAxisDoubles control. + /// </summary> + /// <param name="sender">The source of the event.</param> + /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param> + private void XAxisDoubles_Loaded(object sender, RoutedEventArgs e) + { + DrawTicks(); + } + + /// <summary> + /// Gets or sets the number of ticks. + /// </summary> + public int Ticks + { + get { return (int)GetValue(TicksProperty); } + set { SetValue(TicksProperty, value); } + } + public static readonly DependencyProperty TicksProperty = + DependencyProperty.Register("Ticks", typeof(int), typeof(XAxisDoubles), new PropertyMetadata(8, (d, e) => (d as XAxisDoubles).DrawTicks())); + + /// <summary> + /// Gets or sets the minimum. + /// </summary> + public double Minimum + { + get { return (double)GetValue(MinimumProperty); } + set { SetValue(MinimumProperty, value); } + } + public static readonly DependencyProperty MinimumProperty = + DependencyProperty.Register("Minimum", typeof(double), typeof(XAxisDoubles), new PropertyMetadata(0.0, (d, e) => (d as XAxisDoubles).DrawTicks())); + + /// <summary> + /// Gets or sets the maximum. + /// </summary> + public double Maximum + { + get { return (double)GetValue(MaximumProperty); } + set { SetValue(MaximumProperty, value); } + } + public static readonly DependencyProperty MaximumProperty = + DependencyProperty.Register("Maximum", typeof(double), typeof(XAxisDoubles), new PropertyMetadata(100.0, (d, e) => (d as XAxisDoubles).DrawTicks())); + + /// <summary> + /// Gets or sets the string format. + /// </summary> + public String StringFormat + { + get { return (String)GetValue(StringFormatProperty); } + set { SetValue(StringFormatProperty, value); } + } + public static readonly DependencyProperty StringFormatProperty = + DependencyProperty.Register("StringFormat", typeof(String), typeof(XAxisDoubles), new PropertyMetadata(null)); + + /// <summary> + /// Draws the labels. + /// </summary> + private void DrawTicks() + { + grid.ColumnDefinitions.Clear(); + grid.Children.Clear(); + grid.ClipToBounds = false; + + var steps = Enumerable.Range(0, Ticks) + .Select(i => Minimum + (Maximum - Minimum) * ((double)i / (Ticks - 1))).ToList(); + + for (int i = 0; i < Ticks; i++) + { + if (i == Ticks - 1) + { + var container = AddLabel(steps[i].ToString(StringFormat != null ? StringFormat : "0.0"), i); + container.HorizontalAlignment = HorizontalAlignment.Right; + grid.Children.Add(container); + container.Loaded += (x, y) => + { + container.Margin = new Thickness(0, 0, (container.ActualWidth / 2) * -1, 0); + }; + } + else + { + + ColumnDefinition column = new ColumnDefinition(); + column.Width = new GridLength(1, GridUnitType.Star); + grid.ColumnDefinitions.Add(column); + var container = AddLabel(steps[i].ToString(StringFormat != null ? StringFormat : "0.0"), i); + grid.Children.Add(container); + container.Loaded += (x, y) => + { + container.Margin = new Thickness((container.ActualWidth / 2) * -1, 0, 0, 0); + }; + } + } + } + + /// <summary> + /// Adds the label. + /// </summary> + /// <param name="text">The text.</param> + /// <param name="index">The index.</param> + /// <returns></returns> + private ContentControl AddLabel(String text, int index) + { + ContentControl label = new ContentControl(); + label.Content = text; + label.VerticalAlignment = System.Windows.VerticalAlignment.Top; + label.HorizontalAlignment = System.Windows.HorizontalAlignment.Left; + Grid.SetColumn(label, index); + return label; + } + } +} diff --git a/Software/Visual_Studio/Tango.Visuals/Components/XAxisLabels.xaml b/Software/Visual_Studio/Tango.Visuals/Components/XAxisLabels.xaml new file mode 100644 index 000000000..57513ffac --- /dev/null +++ b/Software/Visual_Studio/Tango.Visuals/Components/XAxisLabels.xaml @@ -0,0 +1,11 @@ +<UserControl x:ClassModifier="internal" x:Class="Tango.Visuals.Components.XAxisLabels" + xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + mc:Ignorable="d" + d:DesignHeight="300" d:DesignWidth="100"> + <Grid x:Name="grid"> + + </Grid> +</UserControl> diff --git a/Software/Visual_Studio/Tango.Visuals/Components/XAxisLabels.xaml.cs b/Software/Visual_Studio/Tango.Visuals/Components/XAxisLabels.xaml.cs new file mode 100644 index 000000000..cc2e1297c --- /dev/null +++ b/Software/Visual_Studio/Tango.Visuals/Components/XAxisLabels.xaml.cs @@ -0,0 +1,147 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Globalization; +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 +{ + /// <summary> + /// Interaction logic for YAxisLabels.xaml + /// </summary> + internal partial class XAxisLabels : UserControl + { + #region Constructors + + /// <summary> + /// Initializes a new instance of the <see cref="XAxisLabels"/> class. + /// </summary> + public XAxisLabels() + { + InitializeComponent(); + this.Loaded += YAxisLabels_Loaded; + } + + #endregion + + #region Properties + + /// <summary> + /// Gets or sets the labels. + /// </summary> + /// <value> + /// The labels. + /// </value> + public ObservableCollection<Object> Labels + { + get { return (ObservableCollection<Object>)GetValue(LabelsProperty); } + set { SetValue(LabelsProperty, value); } + } + public static readonly DependencyProperty LabelsProperty = + DependencyProperty.Register("Labels", typeof(ObservableCollection<Object>), typeof(XAxisLabels), new PropertyMetadata(new ObservableCollection<Object>())); + + /// <summary> + /// Gets or sets the label template. + /// </summary> + /// <value> + /// The label template. + /// </value> + public DataTemplate LabelTemplate + { + get { return (DataTemplate)GetValue(LabelTemplateProperty); } + set { SetValue(LabelTemplateProperty, value); } + } + public static readonly DependencyProperty LabelTemplateProperty = + DependencyProperty.Register("LabelTemplate", typeof(DataTemplate), typeof(XAxisLabels), new PropertyMetadata(null)); + + #endregion + + #region Event Handlers + + private void YAxisLabels_Loaded(object sender, RoutedEventArgs e) + { + DrawLabels(); + } + + #endregion + + #region Methods + + /// <summary> + /// Draws the labels. + /// </summary> + private void DrawLabels() + { + grid.ColumnDefinitions.Clear(); + grid.Children.Clear(); + grid.ClipToBounds = false; + + if (Labels == null) return; + + for (int i = 0; i < Labels.Count; i++) + { + if (i == Labels.Count - 1) + { + var container = AddLabel(Labels[i].ToString(), i); + container.HorizontalAlignment = System.Windows.HorizontalAlignment.Right; + grid.Children.Add(container); + container.Loaded += (x, y) => + { + container.Margin = new Thickness(0, 0, (container.ActualHeight / 2) * -1, 0); + }; + } + else + { + + ColumnDefinition column = new ColumnDefinition(); + column.Width = new GridLength(1, GridUnitType.Star); + grid.ColumnDefinitions.Add(column); + var container = AddLabel(Labels[i].ToString(), i); + grid.Children.Add(container); + container.Loaded += (x, y) => + { + container.Margin = new Thickness((container.ActualHeight / 2) * -1, 0, 0, 0); + }; + } + } + } + + /// <summary> + /// Adds the label. + /// </summary> + /// <param name="text">The text.</param> + /// <param name="index">The index.</param> + /// <returns></returns> + private ContentControl AddLabel(String text, int index) + { + ContentControl label = new ContentControl(); + label.Content = text; + label.VerticalAlignment = System.Windows.VerticalAlignment.Stretch; + label.HorizontalAlignment = System.Windows.HorizontalAlignment.Left; + + label.LayoutTransform = new RotateTransform(270); + + Grid.SetColumn(label, index); + + if (LabelTemplate != null) + { + label.ContentTemplate = LabelTemplate; + } + + return label; + } + + #endregion + } +} diff --git a/Software/Visual_Studio/Tango.Visuals/Components/XAxisTicks.xaml b/Software/Visual_Studio/Tango.Visuals/Components/XAxisTicks.xaml new file mode 100644 index 000000000..779148155 --- /dev/null +++ b/Software/Visual_Studio/Tango.Visuals/Components/XAxisTicks.xaml @@ -0,0 +1,11 @@ +<UserControl x:ClassModifier="internal" x:Class="Tango.Visuals.Components.XAxisTicks" + xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + mc:Ignorable="d" + d:DesignHeight="300" d:DesignWidth="20"> + <Grid x:Name="grid"> + + </Grid> +</UserControl> diff --git a/Software/Visual_Studio/Tango.Visuals/Components/XAxisTicks.xaml.cs b/Software/Visual_Studio/Tango.Visuals/Components/XAxisTicks.xaml.cs new file mode 100644 index 000000000..cc8e9660f --- /dev/null +++ b/Software/Visual_Studio/Tango.Visuals/Components/XAxisTicks.xaml.cs @@ -0,0 +1,137 @@ +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 +{ + /// <summary> + /// Interaction logic for TicksAxis.xaml + /// </summary> + internal partial class XAxisTicks : UserControl + { + + #region Constructors + + /// <summary> + /// Initializes a new instance of the <see cref="XAxisTicks"/> class. + /// </summary> + public XAxisTicks() + { + InitializeComponent(); + this.Loaded += TicksAxis_Loaded; + } + + #endregion + + #region Event Handlers + + /// <summary> + /// Handles the Loaded event of the TicksAxis control. + /// </summary> + /// <param name="sender">The source of the event.</param> + /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param> + private void TicksAxis_Loaded(object sender, RoutedEventArgs e) + { + DrawTicks(); + } + + #endregion + + #region Properties + + /// <summary> + /// Gets or sets the ticks. + /// </summary> + /// <value> + /// The ticks. + /// </value> + 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)); + + /// <summary> + /// Gets or sets the tick template. + /// </summary> + /// <value> + /// The tick template. + /// </value> + 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 + + /// <summary> + /// Draws the ticks. + /// </summary> + 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); + } + } + } + + /// <summary> + /// Adds the tick. + /// </summary> + /// <param name="value">The value.</param> + /// <param name="index">The index.</param> + /// <returns></returns> + 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 + + } +} diff --git a/Software/Visual_Studio/Tango.Visuals/Components/YAxisLabels.xaml b/Software/Visual_Studio/Tango.Visuals/Components/YAxisLabels.xaml new file mode 100644 index 000000000..16d72ca56 --- /dev/null +++ b/Software/Visual_Studio/Tango.Visuals/Components/YAxisLabels.xaml @@ -0,0 +1,11 @@ +<UserControl x:ClassModifier="internal" x:Class="Tango.Visuals.Components.YAxisLabels" + xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + mc:Ignorable="d" + d:DesignHeight="300" d:DesignWidth="100"> + <Grid x:Name="grid"> + + </Grid> +</UserControl> diff --git a/Software/Visual_Studio/Tango.Visuals/Components/YAxisLabels.xaml.cs b/Software/Visual_Studio/Tango.Visuals/Components/YAxisLabels.xaml.cs new file mode 100644 index 000000000..21d32faf4 --- /dev/null +++ b/Software/Visual_Studio/Tango.Visuals/Components/YAxisLabels.xaml.cs @@ -0,0 +1,149 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Globalization; +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 +{ + /// <summary> + /// Interaction logic for YAxisLabels.xaml + /// </summary> + internal partial class YAxisLabels : UserControl + { + #region Constructors + + /// <summary> + /// Initializes a new instance of the <see cref="YAxisLabels"/> class. + /// </summary> + public YAxisLabels() + { + InitializeComponent(); + this.Loaded += YAxisLabels_Loaded; + } + + #endregion + + #region Properties + + /// <summary> + /// Gets or sets the labels. + /// </summary> + /// <value> + /// The labels. + /// </value> + public ObservableCollection<Object> Labels + { + get { return (ObservableCollection<Object>)GetValue(LabelsProperty); } + set { SetValue(LabelsProperty, value); } + } + public static readonly DependencyProperty LabelsProperty = + DependencyProperty.Register("Labels", typeof(ObservableCollection<Object>), typeof(YAxisLabels), new PropertyMetadata(new ObservableCollection<Object>())); + + /// <summary> + /// Gets or sets the label template. + /// </summary> + /// <value> + /// The label template. + /// </value> + public DataTemplate LabelTemplate + { + get { return (DataTemplate)GetValue(LabelTemplateProperty); } + set { SetValue(LabelTemplateProperty, value); } + } + public static readonly DependencyProperty LabelTemplateProperty = + DependencyProperty.Register("LabelTemplate", typeof(DataTemplate), typeof(YAxisLabels), new PropertyMetadata(null)); + + #endregion + + #region Event Handlers + + /// <summary> + /// Handles the Loaded event of the YAxisLabels control. + /// </summary> + /// <param name="sender">The source of the event.</param> + /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param> + private void YAxisLabels_Loaded(object sender, RoutedEventArgs e) + { + DrawLabels(); + } + + #endregion + + #region Methods + + /// <summary> + /// Draws the labels. + /// </summary> + private void DrawLabels() + { + grid.RowDefinitions.Clear(); + grid.Children.Clear(); + grid.ClipToBounds = false; + + if (Labels == null) return; + + for (int i = 0; i < Labels.Count; i++) + { + if (i == Labels.Count - 1) + { + var container = AddLabel(Labels[i].ToString(), i); + container.VerticalAlignment = System.Windows.VerticalAlignment.Bottom; + grid.Children.Add(container); + container.Loaded += (x, y) => + { + container.Margin = new Thickness(0, 0, 0, (container.ActualHeight / 2) * -1); + }; + } + else + { + + RowDefinition row = new RowDefinition(); + row.Height = new GridLength(1, GridUnitType.Star); + grid.RowDefinitions.Add(row); + var container = AddLabel(Labels[i].ToString(), i); + grid.Children.Add(container); + container.Loaded += (x, y) => + { + container.Margin = new Thickness(0, (container.ActualHeight / 2) * -1, 0, 0); + }; + } + } + } + + /// <summary> + /// Adds the label. + /// </summary> + /// <param name="text">The text.</param> + /// <param name="index">The index.</param> + /// <returns></returns> + private ContentControl AddLabel(String text, int index) + { + ContentControl label = new ContentControl(); + label.Content = text; + label.VerticalAlignment = System.Windows.VerticalAlignment.Top; + label.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch; + Grid.SetRow(label, index); + + if (LabelTemplate != null) + { + label.ContentTemplate = LabelTemplate; + } + + return label; + } + + #endregion + } +} |
