aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.CodeGeneration/Templates/ObservablesAdapterFile.cshtml
blob: f6a4a87930c1c00644ce88dc3ab8f838a7c9f0c2 (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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Tango Observables Generator
// 
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated. Do not modify!
// </auto-generated>
//------------------------------------------------------------------------------

using System.Collections.ObjectModel;
using System.ComponentModel;
using Tango.BL.Entities;

namespace Tango.BL
{
    public partial class @(Model.Name)
    {
        @foreach (var prop in Model.Properties)
        {
    <div>
        private @(prop.Type) _@(prop.Name.ToLower());
        /// <summary>
        /// Gets or sets the @(prop.Name).
        /// </summary>
        public @(prop.Type) @(prop.Name)
        {
        get { return _@(prop.Name.ToLower()); }
        set { _@(prop.Name.ToLower()) = value; RaisePropertyChanged(nameof(@(prop.Name))); }
        }

        private ICollectionView _@(prop.Name.ToLower())ViewSource;
        /// <summary>
        /// Gets or sets the @(prop.Name) View Source.
        ///</summary>
        public ICollectionView @(prop.Name)ViewSource
        {
        get { return _@(prop.Name.ToLower())ViewSource; }
        set { _@(prop.Name.ToLower())ViewSource = value; RaisePropertyChanged(nameof(@(prop.Name)ViewSource)); }
        }
    </div>
        }

        /// <summary>
        /// Initialize collection sources.
        /// </summary>
        private void InitCollectionSources()
        {
            @foreach (var prop in Model.Properties)
            {
               <div>
                   @(prop.Name)ViewSource = CreateCollectionView(@(prop.Name));
               </div>
            }
        }
    }
}
ame.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.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Markup;
using System.Windows.Shapes;
using System.Windows.Threading;
using Tango.Core.Threading;

namespace Tango.Touch.Controls
{
    [ContentProperty(nameof(Content))]
    public class TouchVirtualizedContentReplaceControl : Control
    {
        private LightTouchScrollViewer _scrollViewer;
        private Border _innerBorder;
        private ActionTimer _updateTimer;
        private Point _location;
        private bool _loaded;
        private Image _replaceContent;
        private FrameworkElement _element;
        private INameScopeDictionary _parentNameScope;

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

        public bool CanMovePosition
        {
            get { return (bool)GetValue(CanMovePositionProperty); }
            set { SetValue(CanMovePositionProperty, value); }
        }
        public static readonly DependencyProperty CanMovePositionProperty =
            DependencyProperty.Register("CanMovePosition", typeof(bool), typeof(TouchVirtualizedContentReplaceControl), new PropertyMetadata(false));

        public LightTouchDataGrid DataGrid
        {
            get { return (LightTouchDataGrid)GetValue(DataGridProperty); }
            set { SetValue(DataGridProperty, value); }
        }
        public static readonly DependencyProperty DataGridProperty =
            DependencyProperty.Register("DataGrid", typeof(LightTouchDataGrid), typeof(TouchVirtualizedContentReplaceControl), new PropertyMetadata(null));

        public bool Disconnect
        {
            get { return (bool)GetValue(DisconnectProperty); }
            set { SetValue(DisconnectProperty, value); }
        }
        public static readonly DependencyProperty DisconnectProperty =
            DependencyProperty.Register("Disconnect", typeof(bool), typeof(TouchVirtualizedContentReplaceControl), new PropertyMetadata(true));

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

        public TouchVirtualizedContentReplaceControl()
        {
            _replaceContent = new Image();
            _updateTimer = new ActionTimer(TimeSpan.FromMilliseconds(100));
            Loaded += TouchVirtualizedContentControl_Loaded;
        }

        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
            _innerBorder = GetTemplateChild("PART_innerBorder") as Border;
            _innerBorder.Child = _replaceContent;
        }

        private void TouchVirtualizedContentControl_Loaded(object sender, System.Windows.RoutedEventArgs e)
        {
            _scrollViewer = this.FindAncestor<LightTouchScrollViewer>();
            _scrollViewer.Scrolling += _scrollViewer_Scrolling;

            _parentNameScope = NameScope.GetNameScope(this.FindAncestor<UserControl>()) as INameScopeDictionary;

            if (DataGrid != null)
            {
                DataGrid.SortingChanged += DataGrid_SortingChanged;
                DataGrid.FilterChanged += DataGrid_FilterChanged;
            }

            _location = this.TranslatePoint(new Point(0, 0), _scrollViewer.GetContentGrid());

            _scrollViewer.GetContentGrid().SizeChanged += TouchVirtualizedContentControl_SizeChanged;

            ApplyVirtualization();
            _loaded = true;
        }

        private void DataGrid_FilterChanged(object sender, EventArgs e)
        {
            InvalidateVirtualization();
        }

        private void DataGrid_SortingChanged(object sender, EventArgs e)
        {
            InvalidateVirtualization();
        }

        private void TouchVirtualizedContentControl_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            InvalidateVirtualization();
        }

        private void _scrollViewer_Scrolling(object sender, DoubleValueChangedEventArgs e)
        {
            if (_loaded)
            {
                ApplyVirtualization();
            }
        }

        private void InvalidateVirtualization()
        {
            _updateTimer.ResetReplace(() =>
            {
                Dispatcher.Invoke(new Action(() =>
                {
                    _location = this.TranslatePoint(new Point(0, 0), _scrollViewer.GetContentGrid());
                    ApplyVirtualization();
                }));
            });
        }

        private void ApplyVirtualization()
        {
            if (!Disconnect && _element != null)
            {
                _updateTimer.Dispose();
                return;
            }

            var _border_viewport = _scrollViewer.GetViewportBorder();

            if (CanMovePosition)
            {
                _location = this.TranslatePoint(new Point(0, 0), _scrollViewer.GetContentGrid());
            }

            Rect bounds = new Rect(_location.X, _location.Y, ActualWidth, ActualHeight);
            Rect rect = new Rect(0.0, _scrollViewer.GetScrollPosition(), _border_viewport.ActualWidth, _border_viewport.ActualHeight);

            if (_innerBorder != null)
            {
                if (bounds.IntersectsWith(rect))
                {
                    if (Disconnect || _element == null)
                    {
                        if (_innerBorder.Child == _replaceContent || _element == null)
                        {
                            _element = Content.LoadContent() as FrameworkElement;

                            if (_parentNameScope != null)
                            {
                                NameScope.SetNameScope(_element, _parentNameScope);
                            }

                            _innerBorder.Child = _element;
                            _innerBorder.Height = double.NaN;
                        }
                    }
                }
                else
                {
                    if (Disconnect)
                    {
                        if (_innerBorder.Child == _element)
                        {
                            double height = _element != null ? _element.ActualHeight : MinHeight;
                            _innerBorder.Child = _replaceContent;
                            _innerBorder.Height = height;
                        }
                    }
                }
            }
        }
    }
}