aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Scripting/TestApp/App.xaml.cs
blob: f70c274287fc91e633d6cab983bc6a4dc3f655e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;

namespace TestApp
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
    }
}
#dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
using System;
using System.Collections;
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.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Tango.SharedUI.Helpers;

namespace Tango.Touch.Controls
{
    [TemplatePart(Name = PART_Rectangle, Type = typeof(Rectangle))]
    public class TouchNavigationLinks : ListBox
    {
        private const string PART_Rectangle = "PART_Rectangle";
        private Line _line;
        private Object _lastSelectedItem;

        static TouchNavigationLinks()
        {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(TouchNavigationLinks), new FrameworkPropertyMetadata(typeof(TouchNavigationLinks)));
        }

        public TouchNavigationLinks()
        {
            SelectionChanged += NavigationLinks_SelectionChanged;
            Loaded += (_, __) => MoveLineToSelectedItem();
        }

        public override void OnApplyTemplate()
        {
            _line = GetTemplateChild(PART_Rectangle) as Line;
        }

        private void NavigationLinks_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            MoveLineToSelectedItem();
        }

        private void MoveLineToSelectedItem()
        {
            if (SelectedItem != null)
            {
                var container = ItemContainerGenerator.ContainerFromItem(SelectedItem) as FrameworkElement;

                ContentPresenter presenter = container.FindChild<ContentPresenter>().FindChild<ContentPresenter>();

                if (presenter != null)
                {
                    Point relativePoint = presenter.TransformToAncestor(this).Transform(new Point(0, 0));
                    double width = presenter.ActualWidth;

                    if (_lastSelectedItem != null && Items.IndexOf(SelectedItem) > Items.IndexOf(_lastSelectedItem))
                    {
                        DoubleAnimation aniX2 = new DoubleAnimation();
                        aniX2.To = relativePoint.X + width;
                        aniX2.Duration = TimeSpan.FromSeconds(0.2);
                        _line.BeginAnimation(Line.X2Property, aniX2);

                        DoubleAnimation aniX1 = new DoubleAnimation();
                        aniX1.To = relativePoint.X;
                        aniX1.BeginTime = TimeSpan.FromSeconds(0.2);
                        aniX1.Duration = TimeSpan.FromSeconds(0.1);
                        _line.BeginAnimation(Line.X1Property, aniX1);
                    }
                    else
                    {
                        DoubleAnimation aniX1 = new DoubleAnimation();
                        aniX1.To = relativePoint.X;
                        aniX1.Duration = TimeSpan.FromSeconds(0.2);
                        _line.BeginAnimation(Line.X1Property, aniX1);

                        DoubleAnimation aniX2 = new DoubleAnimation();
                        aniX2.To = relativePoint.X + width;
                        aniX2.BeginTime = TimeSpan.FromSeconds(0.2);
                        aniX2.Duration = TimeSpan.FromSeconds(0.1);
                        _line.BeginAnimation(Line.X2Property, aniX2);
                    }
                }
            }

            _lastSelectedItem = SelectedItem;
        }
    }
}