aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Views/AddressView.xaml
blob: 937cf14ddf73130f0486308ce80df4a2397206cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<UserControl x:Class="Tango.MachineStudio.UsersAndRoles.Views.AddressView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:vm="clr-namespace:Tango.MachineStudio.UsersAndRoles.ViewModels"
             xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
             xmlns:autoComplete="clr-namespace:Tango.AutoComplete.Editors;assembly=Tango.AutoComplete"
             xmlns:controls="clr-namespace:Tango.SharedUI.Controls;assembly=Tango.SharedUI"
             xmlns:mahApps="http://metro.mahapps.com/winfx/xaml/controls"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:entities="clr-namespace:Tango.BL.Entities;assembly=Tango.BL"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:Tango.MachineStudio.UsersAndRoles.Views"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300" d:DataContext="{d:DesignInstance Type=entities:Address, IsDesignTimeCreatable=False}">
    <Grid>
        <controls:TableGrid>
            <TextBlock Text="COUNTRY"></TextBlock>
            <TextBox Text="{Binding Country}" />
            <TextBlock Text="COUNTRY CODE"></TextBlock>
            <TextBox IsReadOnly="True" Text="{Binding CountryCode}"></TextBox>
            <TextBlock Text="STATE"></TextBlock>
            <TextBox Text="{Binding State}"></TextBox>
            <TextBlock Text="CITY"></TextBlock>
            <TextBox Text="{Binding City}" />
            <TextBlock Text="POSTAL CODE"></TextBlock>
            <TextBox Text="{Binding PostalCode}"></TextBox>
            <TextBlock Text="LOCALITY"></TextBlock>
            <TextBox Text="{Binding Locality}" />
            <TextBlock Text="ADDRESS"></TextBlock>
            <TextBox Text="{Binding AddressString}"></TextBox>
        </controls:TableGrid>
    </Grid>
</UserControl>
neric.Error */ .highlight .gh { color: #333333 } /* Generic.Heading */ .highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */ .highlight .go { color: #888888 } /* Generic.Output */ .highlight .gp { color: #555555 } /* Generic.Prompt */ .highlight .gs { font-weight: bold } /* Generic.Strong */ .highlight .gu { color: #666666 } /* Generic.Subheading */ .highlight .gt { color: #aa0000 } /* Generic.Traceback */ .highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */ .highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */ .highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */ .highlight .kp { color: #008800 } /* Keyword.Pseudo */ .highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #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.Diagnostics;
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.Core.EventArguments;

namespace Tango.Touch.Controls
{
    public class TouchNotificationBar : ContentControl
    {
        private bool _isMouseDown;
        private Point _mouseDownLocation;
        private bool _isMoving;
        private Point _downLocation;
        private TouchDevice _touchDevice;
        private double _last_manipulation_delta;

        private Border border_notifications;
        private Grid grid_container;

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

        public double MinNotificationHeight
        {
            get { return (double)GetValue(MinNotificationHeightProperty); }
            set { SetValue(MinNotificationHeightProperty, value); }
        }
        public static readonly DependencyProperty MinNotificationHeightProperty =
            DependencyProperty.Register("MinNotificationHeight", typeof(double), typeof(TouchNotificationBar), new PropertyMetadata(60.0));

        public double MaxNotificationHeight
        {
            get { return (double)GetValue(MaxNotificationHeightProperty); }
            set { SetValue(MaxNotificationHeightProperty, value); }
        }
        public static readonly DependencyProperty MaxNotificationHeightProperty =
            DependencyProperty.Register("MaxNotificationHeight", typeof(double), typeof(TouchNotificationBar), new PropertyMetadata(100.0));

        public Thickness NotificationPadding
        {
            get { return (Thickness)GetValue(NotificationPaddingProperty); }
            set { SetValue(NotificationPaddingProperty, value); }
        }
        public static readonly DependencyProperty NotificationPaddingProperty =
            DependencyProperty.Register("NotificationPadding", typeof(Thickness), typeof(TouchNotificationBar), new PropertyMetadata(new Thickness(0)));

        public bool HasNotifications
        {
            get { return (bool)GetValue(HasNotificationsProperty); }
            set { SetValue(HasNotificationsProperty, value); }
        }
        public static readonly DependencyProperty HasNotificationsProperty =
            DependencyProperty.Register("HasNotifications", typeof(bool), typeof(TouchNotificationBar), new PropertyMetadata(false, (d, e) => (d as TouchNotificationBar).OnHasNotificationsChanged()));

        public IList Notifications
        {
            get { return (IList)GetValue(NotificationsProperty); }
            set { SetValue(NotificationsProperty, value); }
        }
        public static readonly DependencyProperty NotificationsProperty =
            DependencyProperty.Register("Notifications", typeof(IList), typeof(TouchNotificationBar), new PropertyMetadata(null));

        public DataTemplate NotificationTemplate
        {
            get { return (DataTemplate)GetValue(NotificationTemplateProperty); }
            set { SetValue(NotificationTemplateProperty, value); }
        }
        public static readonly DependencyProperty NotificationTemplateProperty =
            DependencyProperty.Register("NotificationTemplate", typeof(DataTemplate), typeof(TouchNotificationBar), new PropertyMetadata(null));

        public double NotificationHeight
        {
            get { return (double)GetValue(NotificationHeightProperty); }
            set { SetValue(NotificationHeightProperty, value); }
        }
        public static readonly DependencyProperty NotificationHeightProperty =
            DependencyProperty.Register("NotificationHeight", typeof(double), typeof(TouchNotificationBar), new PropertyMetadata(0.0));


        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
            border_notifications = GetTemplateChild("PART_BorderNotifications") as Border;
            grid_container = GetTemplateChild("PART_Grid_Container") as Grid;

            //border_notifications.IsManipulationEnabled = true;
            border_notifications.RegisterForPreviewMouseOrTouchDown(GridNotificationMouseDown);
            border_notifications.RegisterForMouseOrTouchMove(GridNotificationMouseMove);
            border_notifications.RegisterForPreviewMouseOrTouchUp(GridNotificationMouseUp);

            border_notifications.ManipulationDelta += Border_notifications_ManipulationDelta;

            border_notifications.SizeChanged += Border_notifications_SizeChanged;
        }

        private void Border_notifications_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
        {
            if (e.DeltaManipulation.Translation.Y != 0)
            {
                _last_manipulation_delta = e.DeltaManipulation.Translation.Y;
            }
        }

        private void Border_notifications_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            double maxPadding = 150;
            NotificationHeight = (border_notifications.ActualHeight / ActualHeight) * maxPadding;
        }

        private void OnHasNotificationsChanged()
        {
            DoubleAnimation ani = new DoubleAnimation();
            ani.Duration = TimeSpan.FromSeconds(0.2);

            if (HasNotifications)
            {
                ani.To = MinNotificationHeight;
            }
            else
            {
                ani.To = 0;
                CloseNotifications();
            }

            grid_container.BeginAnimation(Grid.MinHeightProperty, ani);
        }

        private void OpenNotifications()
        {
            DoubleAnimation ani = new DoubleAnimation();
            ani.DecelerationRatio = 1;
            ani.Duration = TimeSpan.FromSeconds(0.2);

            if (double.IsNaN(border_notifications.Height))
            {
                border_notifications.Height = border_notifications.ActualHeight;
            }

            border_notifications.MaxHeight = this.ActualHeight;
            ani.To = this.ActualHeight;
            border_notifications.BeginAnimation(Grid.HeightProperty, ani);
        }

        private void CloseNotifications()
        {
            DoubleAnimation ani = new DoubleAnimation();
            ani.Duration = TimeSpan.FromSeconds(0.2);
            ani.AccelerationRatio = 1;

            ani.From = border_notifications.ActualHeight;
            ani.To = MinNotificationHeight;

            ani.Completed += (_, __) =>
            {
                border_notifications.BorderThickness = new Thickness(0);
                border_notifications.BeginAnimation(Border.HeightProperty, null);
                border_notifications.Height = double.NaN;
            };

            border_notifications.BeginAnimation(Border.MaxHeightProperty, ani);
            border_notifications.BeginAnimation(Border.HeightProperty, ani);

            ThicknessAnimation tAni = new ThicknessAnimation();
            tAni.Duration = TimeSpan.FromSeconds(0.3);
            tAni.To = new Thickness(0);
            border_notifications.BeginAnimation(Border.BorderThicknessProperty, tAni);
        }

        private void GridNotificationMouseUp(object sender, MouseOrTouchEventArgs e)
        {
            _isMouseDown = false;

            if (_isMoving)
            {
                if (_touchDevice != null)
                {
                    border_notifications.ReleaseTouchCapture(_touchDevice);
                    _touchDevice = null;
                }
                else
                {
                    border_notifications.ReleaseMouseCapture();
                }

                e.Handled = true;
                _isMoving = false;
                DoubleAnimation ani = new DoubleAnimation();
                ani.Duration = TimeSpan.FromSeconds(0.2);

                if (e.GetPosition(this).Y > ActualHeight / 2 || _last_manipulation_delta > 20)
                {
                    OpenNotifications();
                }
                else if (e.GetPosition(this).Y < ActualHeight / 2 || _last_manipulation_delta < 20)
                {
                    CloseNotifications();
                }
            }
        }

        private void GridNotificationMouseMove(object sender, MouseOrTouchEventArgs e)
        {
            if (_isMouseDown)
            {
                if (Math.Abs(e.Location.Y - _downLocation.Y) > 5)
                {
                    _isMoving = true;
                }

                if (_isMoving)
                {
                    if (e.TouchDevice != null)
                    {
                        border_notifications.CaptureTouch(e.TouchDevice);
                    }
                    else
                    {
                        Mouse.Capture(border_notifications);
                    }
                    border_notifications.Height = Math.Max(e.Location.Y + _mouseDownLocation.Y, MinNotificationHeight);
                    border_notifications.MaxHeight = Math.Max(e.Location.Y + _mouseDownLocation.Y, MinNotificationHeight);
                    border_notifications.BeginAnimation(Border.HeightProperty, null);
                    border_notifications.BeginAnimation(Border.MaxHeightProperty, null);

                    border_notifications.BeginAnimation(Border.BorderThicknessProperty, null);
                    if (border_notifications.ActualHeight > MinNotificationHeight)
                    {
                        border_notifications.BorderThickness = new Thickness(0, 0, 0, 20);
                    }
                    else
                    {
                        border_notifications.BorderThickness = new Thickness(0);
                    }
                }
            }
        }

        private void GridNotificationMouseDown(object sender, MouseOrTouchEventArgs e)
        {
            _mouseDownLocation = new Point(e.Location.X, border_notifications.MaxHeight - e.Location.Y);
            _downLocation = e.Location;
            _isMouseDown = true;
        }
    }
}