diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2019-04-22 19:50:30 +0300 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2019-04-22 19:50:30 +0300 |
| commit | ffbda2b8be71d4942e0d4af2f53b5bde357c72e2 (patch) | |
| tree | 6656196be6ecaccaed9b39aaf1a75619aeec194b /Software/Visual_Studio/Tango.Touch/Controls/TouchVirtualizedContentControl.cs | |
| parent | c2945492e7c4d168c36b632d1f28dd8ca569b5ac (diff) | |
| parent | 0a63ef17afb9afe60e4ea98cff86dda7fbdad1f6 (diff) | |
| download | Tango-ffbda2b8be71d4942e0d4af2f53b5bde357c72e2.tar.gz Tango-ffbda2b8be71d4942e0d4af2f53b5bde357c72e2.zip | |
MERGE!
Diffstat (limited to 'Software/Visual_Studio/Tango.Touch/Controls/TouchVirtualizedContentControl.cs')
| -rw-r--r-- | Software/Visual_Studio/Tango.Touch/Controls/TouchVirtualizedContentControl.cs | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/Software/Visual_Studio/Tango.Touch/Controls/TouchVirtualizedContentControl.cs b/Software/Visual_Studio/Tango.Touch/Controls/TouchVirtualizedContentControl.cs new file mode 100644 index 000000000..02240ecc8 --- /dev/null +++ b/Software/Visual_Studio/Tango.Touch/Controls/TouchVirtualizedContentControl.cs @@ -0,0 +1,99 @@ +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.Markup; +using System.Windows.Shapes; +using Tango.Core.Threading; + +namespace Tango.Touch.Controls +{ + [ContentProperty(nameof(Content))] + public class TouchVirtualizedContentControl : Control + { + private LightTouchScrollViewer _scrollViewer; + private ContentPresenter _innerBorder; + private ActionTimer _updateTimer; + private Point _location; + private bool _loaded; + + public UIElement Content + { + get { return (UIElement)GetValue(ContentProperty); } + set { SetValue(ContentProperty, value); } + } + public static readonly DependencyProperty ContentProperty = + DependencyProperty.Register("Content", typeof(UIElement), typeof(TouchVirtualizedContentControl), new PropertyMetadata(null)); + + static TouchVirtualizedContentControl() + { + DefaultStyleKeyProperty.OverrideMetadata(typeof(TouchVirtualizedContentControl), new FrameworkPropertyMetadata(typeof(TouchVirtualizedContentControl))); + } + + public TouchVirtualizedContentControl() + { + _updateTimer = new ActionTimer(TimeSpan.FromMilliseconds(200)); + Loaded += TouchVirtualizedContentControl_Loaded; + } + + public override void OnApplyTemplate() + { + base.OnApplyTemplate(); + _innerBorder = GetTemplateChild("PART_innerBorder") as ContentPresenter; + } + + private void TouchVirtualizedContentControl_Loaded(object sender, System.Windows.RoutedEventArgs e) + { + _scrollViewer = this.FindAncestor<LightTouchScrollViewer>(); + _scrollViewer.Scrolling += _scrollViewer_Scrolling; + + _location = this.TranslatePoint(new Point(0, 0), _scrollViewer); + + ApplyOptimization(); + _loaded = true; + } + + private void _scrollViewer_Scrolling(object sender, DoubleValueChangedEventArgs e) + { + if (_loaded) + { + //_updateTimer.ResetReplace(() => + //{ + // Dispatcher.BeginInvoke(new Action(() => + // { + ApplyOptimization(); + // })); + //}); + } + } + + private void ApplyOptimization() + { + //var _border_viewport = _scrollViewer.GetViewportBorder(); + + //if (_border_viewport.IsAncestorOf(this)) + //{ + // //Point relativeLocation = this.TranslatePoint(new Point(0, 0), _border_viewport); + // //Rect bounds = this.TransformToAncestor(_border_viewport).TransformBounds(new Rect(0.0, 0.0, this.ActualWidth, this.ActualHeight)); + // //Rect rect = new Rect(0.0, 0.0, _border_viewport.ActualWidth, _border_viewport.ActualHeight); + // if (_location.Y > _scrollViewer.GetScrollPosition() && _location.Y < _scrollViewer.GetScrollPosition() + _border_viewport.ActualHeight) + // { + // if (_innerBorder.Visibility == Visibility.Hidden) + // { + // _innerBorder.Visibility = Visibility.Visible; + // } + // } + // else + // { + // if (_innerBorder.Visibility == Visibility.Visible) + // { + // _innerBorder.Visibility = Visibility.Hidden; + // } + // } + //} + } + } +} |
