summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.WP8/ListViewRenderer.cs
blob: 538c529f4854bd9b305cb9d455e839e70f54cf91 (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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Input;
using System.Windows.Media;
using Microsoft.Phone.Controls;
using GestureEventArgs = System.Windows.Input.GestureEventArgs;
using SLButton = System.Windows.Controls.Button;
using SLBinding = System.Windows.Data.Binding;
using System.Collections;
using Xamarin.Forms.Internals;

namespace Xamarin.Forms.Platform.WinPhone
{
	// Fixes a weird crash, don't ask.
	internal class FixedLongListSelector : LongListSelector
	{
		bool _isInPullToRefresh;

		System.Windows.Point _lastPosition;
		double _pullToRefreshStatus;

		public FixedLongListSelector()
		{
			Loaded += OnLoaded;
		}

		public bool IsInPullToRefresh
		{
			get { return _isInPullToRefresh; }
			private set
			{
				if (_isInPullToRefresh == value)
					return;
				_isInPullToRefresh = value;

				if (_isInPullToRefresh)
				{
					EventHandler handler = PullToRefreshStarted;
					if (handler != null)
						handler(this, EventArgs.Empty);
				}
				else
				{
					EventHandler handler = PullToRefreshStatus >= 1 ? PullToRefreshCompleted : PullToRefreshCanceled;
					if (handler != null)
						handler(this, EventArgs.Empty);
					_pullToRefreshStatus = 0;
				}
			}
		}

		public double PullToRefreshStatus
		{
			get { return _pullToRefreshStatus; }
			set
			{
				if (_pullToRefreshStatus == value)
					return;
				_pullToRefreshStatus = value;
				EventHandler handler = PullToRefreshStatusUpdated;
				if (handler != null)
					handler(this, EventArgs.Empty);
			}
		}

		public ViewportControl ViewportControl { get; private set; }

		bool ViewportAtTop
		{
			get { return ViewportControl.Viewport.Top == 0; }
		}

		public override void OnApplyTemplate()
		{
			base.OnApplyTemplate();

			if (ViewportControl != null)
			{
				ViewportControl.ViewportChanged -= OnViewportChanged;
				ViewportControl.ManipulationStateChanged -= OnManipulationStateChanged;
			}

			ViewportControl = (ViewportControl)VisualTreeHelper.GetChild(VisualTreeHelper.GetChild(VisualTreeHelper.GetChild(this, 0), 0), 0);
			ViewportControl.ViewportChanged += OnViewportChanged;
			ViewportControl.ManipulationStateChanged += OnManipulationStateChanged;
		}

		public event EventHandler PullToRefreshCanceled;

		public event EventHandler PullToRefreshCompleted;

		public event EventHandler PullToRefreshStarted;

		public event EventHandler PullToRefreshStatusUpdated;

		protected override System.Windows.Size MeasureOverride(System.Windows.Size availableSize)
		{
			try
			{
				return base.MeasureOverride(availableSize);
			}
			catch (ArgumentException)
			{
				return base.MeasureOverride(availableSize);
			}
		}

		void OnFrameReported(object sender, TouchFrameEventArgs e)
		{
			TouchPoint touchPoint;
			try
			{
				touchPoint = e.GetPrimaryTouchPoint(this);
			}
			catch (Exception)
			{
				return;
			}

			if (touchPoint == null || touchPoint.Action != TouchAction.Move)
				return;

			System.Windows.Point position = touchPoint.Position;

			if (IsInPullToRefresh)
			{
				double delta = position.Y - _lastPosition.Y;
				PullToRefreshStatus += delta / 150.0;
			}

			_lastPosition = position;
		}

		void OnLoaded(object sender, RoutedEventArgs routedEventArgs)
		{
			Loaded -= OnLoaded;
			Unloaded += OnUnloaded;

			Touch.FrameReported += OnFrameReported;
		}

		void OnManipulationStateChanged(object o, ManipulationStateChangedEventArgs args)
		{
			switch (ViewportControl.ManipulationState)
			{
				case ManipulationState.Idle:
					// thing is rested
					IsInPullToRefresh = false;
					break;
				case ManipulationState.Manipulating:
					// user interaction
					IsInPullToRefresh = ViewportAtTop;
					break;
				case ManipulationState.Animating:
					// user let go
					IsInPullToRefresh = false;
					break;
				default:
					throw new ArgumentOutOfRangeException();
			}
		}

		void OnUnloaded(object sender, RoutedEventArgs routedEventArgs)
		{
			Loaded += OnLoaded;
			Unloaded -= OnUnloaded;

			Touch.FrameReported -= OnFrameReported;
		}

		void OnViewportChanged(object o, ViewportChangedEventArgs args)
		{
			if (ViewportControl.ManipulationState == ManipulationState.Manipulating)
				IsInPullToRefresh = ViewportAtTop;
		}
	}

	public class ListViewRenderer : ViewRenderer<ListView, LongListSelector>
	{
		public static readonly DependencyProperty HighlightWhenSelectedProperty = DependencyProperty.RegisterAttached("HighlightWhenSelected", typeof(bool), typeof(ListViewRenderer),
			new PropertyMetadata(false));

		readonly List<Tuple<FrameworkElement, SLBinding, Brush>> _previousHighlights = new List<Tuple<FrameworkElement, SLBinding, Brush>>();

		Animatable _animatable;
		object _fromNative;
		bool _itemNeedsSelecting;
		FixedLongListSelector _listBox;
		System.Windows.Controls.ProgressBar _progressBar;

		ViewportControl _viewport;
		IListViewController Controller => Element;
		ITemplatedItemsView<Cell> TemplatedItemsView => Element;

		public override SizeRequest GetDesiredSize(double widthConstraint, double heightConstraint)
		{
			SizeRequest result = base.GetDesiredSize(widthConstraint, heightConstraint);
			result.Minimum = new Size(40, 40);
			return result;
		}

		public static bool GetHighlightWhenSelected(DependencyObject dependencyObject)
		{
			return (bool)dependencyObject.GetValue(HighlightWhenSelectedProperty);
		}

		public static void SetHighlightWhenSelected(DependencyObject dependencyObject, bool value)
		{
			dependencyObject.SetValue(HighlightWhenSelectedProperty, value);
		}

		protected override System.Windows.Size ArrangeOverride(System.Windows.Size finalSize)
		{
			System.Windows.Size result = base.ArrangeOverride(finalSize);

			_progressBar.Measure(finalSize);
			_progressBar.Arrange(new Rect(0, 0, finalSize.Width, _progressBar.DesiredSize.Height));

			return result;
		}

		protected override void OnElementChanged(ElementChangedEventArgs<ListView> e)
		{
			base.OnElementChanged(e);

			Controller.ScrollToRequested += OnScrollToRequested;

			if (Element.SelectedItem != null)
				_itemNeedsSelecting = true;

			_listBox = new FixedLongListSelector
			{
				DataContext = Element,
				ItemsSource = (IList)TemplatedItemsView.TemplatedItems,
				ItemTemplate = (System.Windows.DataTemplate)System.Windows.Application.Current.Resources["CellTemplate"],
				GroupHeaderTemplate = (System.Windows.DataTemplate)System.Windows.Application.Current.Resources["ListViewHeader"],
				ListHeaderTemplate = (System.Windows.DataTemplate)System.Windows.Application.Current.Resources["View"],
				ListFooterTemplate = (System.Windows.DataTemplate)System.Windows.Application.Current.Resources["View"]
			};
			_listBox.SetBinding(LongListSelector.IsGroupingEnabledProperty, new SLBinding("IsGroupingEnabled"));

			_listBox.SelectionChanged += OnNativeSelectionChanged;
			_listBox.Tap += OnNativeItemTapped;
			_listBox.ItemRealized += OnItemRealized;

			_listBox.PullToRefreshStarted += OnPullToRefreshStarted;
			_listBox.PullToRefreshCompleted += OnPullToRefreshCompleted;
			_listBox.PullToRefreshCanceled += OnPullToRefreshCanceled;
			_listBox.PullToRefreshStatusUpdated += OnPullToRefreshStatusUpdated;

			SetNativeControl(_listBox);

			_progressBar = new System.Windows.Controls.ProgressBar { Maximum = 1, Visibility = Visibility.Collapsed };
			Children.Add(_progressBar);

			UpdateHeader();
			UpdateFooter();
			UpdateJumpList();
		}

		protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
		{
			base.OnElementPropertyChanged(sender, e);

			if (e.PropertyName == ListView.SelectedItemProperty.PropertyName)
				OnItemSelected(Element.SelectedItem);
			else if (e.PropertyName == "HeaderElement")
				UpdateHeader();
			else if (e.PropertyName == "FooterElement")
				UpdateFooter();
			else if ((e.PropertyName == ListView.IsRefreshingProperty.PropertyName) || (e.PropertyName == ListView.IsPullToRefreshEnabledProperty.PropertyName) || (e.PropertyName == "CanRefresh"))
				UpdateIsRefreshing();
			else if (e.PropertyName == "GroupShortNameBinding")
				UpdateJumpList();
		}

		protected override void UpdateNativeWidget()
		{
			base.UpdateNativeWidget();

			if (_progressBar != null)
				_progressBar.Width = Element.Width;
		}

		Cell FindCell(GestureEventArgs e, out FrameworkElement element)
		{
			Cell cell = null;
			element = e.OriginalSource as FrameworkElement;
			if (element != null)
				cell = element.DataContext as Cell;

			if (cell == null)
			{
				System.Windows.Point pos = e.GetPosition(_listBox);
				IEnumerable<UIElement> elements = VisualTreeHelper.FindElementsInHostCoordinates(pos, _listBox);
				foreach (FrameworkElement frameworkElement in elements.OfType<FrameworkElement>())
				{
					if ((cell = frameworkElement.DataContext as Cell) != null)
					{
						element = frameworkElement;
						break;
					}
				}
			}

			return cell;
		}

		static IEnumerable<T> FindDescendants<T>(DependencyObject dobj) where T : DependencyObject
		{
			int count = VisualTreeHelper.GetChildrenCount(dobj);
			for (var i = 0; i < count; i++)
			{
				DependencyObject element = VisualTreeHelper.GetChild(dobj, i);
				if (element is T)
					yield return (T)element;

				foreach (T descendant in FindDescendants<T>(element))
					yield return descendant;
			}
		}

		FrameworkElement FindElement(Cell cell)
		{
			foreach (CellControl selector in FindDescendants<CellControl>(_listBox))
			{
				if (ReferenceEquals(cell, selector.DataContext))
					return selector;
			}

			return null;
		}

		IEnumerable<FrameworkElement> FindHighlight(FrameworkElement element)
		{
			FrameworkElement parent = element;
			while (true)
			{
				element = parent;
				if (element is CellControl)
					break;

				parent = VisualTreeHelper.GetParent(element) as FrameworkElement;
				if (parent == null)
				{
					parent = element;
					break;
				}
			}

			return FindHighlightCore(parent);
		}

		IEnumerable<FrameworkElement> FindHighlightCore(DependencyObject element)
		{
			int children = VisualTreeHelper.GetChildrenCount(element);
			for (var i = 0; i < children; i++)
			{
				DependencyObject child = VisualTreeHelper.GetChild(element, i);

				var label = child as LabelRenderer;
				var childElement = child as FrameworkElement;
				if (childElement != null && (GetHighlightWhenSelected(childElement) || label != null))
				{
					if (label != null)
						yield return label.Control;
					else
						yield return childElement;
				}

				foreach (FrameworkElement recursedElement in FindHighlightCore(childElement))
					yield return recursedElement;
			}
		}

		double GetHeight(Dictionary<System.Windows.DataTemplate, FrameworkElement> reusables, System.Windows.DataTemplate template, object bindingContext)
		{
			double width = Control.ActualWidth;

			FrameworkElement content;
			if (!reusables.TryGetValue(template, out content))
			{
				content = (FrameworkElement)template.LoadContent();

				// Windows Phone refuses to properly bind things on a first pass or even a second pass unless it has different content
				// so we'll force it to cycle here the first time for each template.
				content.DataContext = bindingContext;
				content.Measure(new System.Windows.Size(width, double.PositiveInfinity));
				content.DataContext = null;
				content.Measure(new System.Windows.Size(width, double.PositiveInfinity));

				var control = content as Control;
				if (control != null)
				{
					// Since we're not adding to the visual tree, we need to inherit the font to measure correctly.
					control.FontFamily = Control.FontFamily;
				}

				reusables[template] = content;
			}

			content.DataContext = bindingContext;
			content.Measure(new System.Windows.Size(width, double.PositiveInfinity));
			return content.DesiredSize.Height;
		}

		void OnItemRealized(object sender, ItemRealizationEventArgs e)
		{
			if (!_itemNeedsSelecting)
				return;

			var cell = e.Container.DataContext as Cell;
			if (cell == null || !Equals(cell.BindingContext, Element.SelectedItem))
				return;

			_itemNeedsSelecting = false;
			OnItemSelected(Element.SelectedItem);
		}

		void OnItemSelected(object selectedItem)
		{
			if (_fromNative != null && Equals(selectedItem, _fromNative))
			{
				_fromNative = null;
				return;
			}

			RestorePreviousSelectedVisual();

			if (selectedItem == null)
			{
				_listBox.SelectedItem = selectedItem;
				return;
			}

			IEnumerable<CellControl> items = FindDescendants<CellControl>(_listBox);

			CellControl item = items.FirstOrDefault(i =>
			{
				var cell = (Cell)i.DataContext;
				return Equals(cell.BindingContext, selectedItem);
			});

			if (item == null)
			{
				_itemNeedsSelecting = true;
				return;
			}

			SetSelectedVisual(item);
		}

		void OnNativeItemTapped(object sender, GestureEventArgs e)
		{
			var cell = (Cell)Control.SelectedItem;
			if (cell == null)
				return;

			Cell parentCell = null;

			if (Element.IsGroupingEnabled)
			{
				parentCell = cell.GetGroupHeaderContent<ItemsView<Cell>, Cell>();
			}

			_fromNative = cell.BindingContext;

			if (Element.IsGroupingEnabled)
			{
				Controller.NotifyRowTapped(parentCell.GetIndex<ItemsView<Cell>, Cell>(), cell.GetIndex<ItemsView<Cell>, Cell>(), null);
			}
			else
				Controller.NotifyRowTapped(cell.GetIndex<ItemsView<Cell>, Cell>(), null);
		}

		void OnNativeSelectionChanged(object sender, SelectionChangedEventArgs e)
		{
			if (e.AddedItems.Count == 0)
				return;

			var cell = (Cell)e.AddedItems[0];

			if (cell == null)
			{
				RestorePreviousSelectedVisual();
				return;
			}

			RestorePreviousSelectedVisual();
			FrameworkElement element = FindElement(cell);
			if (element != null)
				SetSelectedVisual(element);
		}

		void OnPullToRefreshCanceled(object sender, EventArgs args)
		{
			if (Element.IsPullToRefreshEnabled && Controller.RefreshAllowed)
				_progressBar.Visibility = Visibility.Collapsed;
		}

		void OnPullToRefreshCompleted(object sender, EventArgs args)
		{
			if (Element.IsPullToRefreshEnabled && Controller.RefreshAllowed)
			{
				_progressBar.IsIndeterminate = true;
				Controller.SendRefreshing();
			}
		}

		void OnPullToRefreshStarted(object sender, EventArgs args)
		{
			if (Element.IsPullToRefreshEnabled && Controller.RefreshAllowed)
			{
				_progressBar.Visibility = Visibility.Visible;
				_progressBar.IsIndeterminate = false;
				_progressBar.Value = Math.Max(0, Math.Min(1, _listBox.PullToRefreshStatus));
			}
		}

		void OnPullToRefreshStatusUpdated(object sender, EventArgs eventArgs)
		{
			if (Element.IsPullToRefreshEnabled && Controller.RefreshAllowed)
				_progressBar.Value = Math.Max(0, Math.Min(1, _listBox.PullToRefreshStatus));
		}

		void OnScrollToRequested(object sender, ScrollToRequestedEventArgs e)
		{
			if (_animatable == null && e.ShouldAnimate)
				_animatable = new Animatable();

			if (_viewport == null)
			{
				// Making sure we're actually loaded
				if (VisualTreeHelper.GetChildrenCount(_listBox) == 0)
				{
					RoutedEventHandler handler = null;
					handler = (o, args) =>
					{
						Control.Loaded -= handler;
						OnScrollToRequested(sender, e);
					};
					Control.Loaded += handler;

					return;
				}
				_viewport = (ViewportControl)VisualTreeHelper.GetChild(VisualTreeHelper.GetChild(VisualTreeHelper.GetChild(_listBox, 0), 0), 0);
				if (_viewport.Viewport.Bottom == 0)
				{
					EventHandler<ViewportChangedEventArgs> viewportChanged = null;
					viewportChanged = (o, args) =>
					{
						if (_viewport.Viewport.Bottom == 0)
							return;

						_viewport.ViewportChanged -= viewportChanged;
						OnScrollToRequested(sender, e);
					};
					_viewport.ViewportChanged += viewportChanged;
					return;
				}
			}

			double y = 0;
			double targetHeight = 0;
			double targetHeaderHeight = 0;

			var templateReusables = new Dictionary<System.Windows.DataTemplate, FrameworkElement>();
			var templatedItems = TemplatedItemsView.TemplatedItems;
			var scrollArgs = (ITemplatedItemsListScrollToRequestedEventArgs)e;

			var found = false;

			if (Element.IsGroupingEnabled)
			{
				for (var g = 0; g < templatedItems.Count; g++)
				{
					if (found)
						break;

					var til = templatedItems.GetGroup(g);

					double headerHeight = GetHeight(templateReusables, Control.GroupHeaderTemplate, til);
					y += headerHeight;

					for (var i = 0; i < til.Count; i++)
					{
						Cell cell = til[i] as Cell;

						double contentHeight = GetHeight(templateReusables, Control.ItemTemplate, cell);

						if ((ReferenceEquals(til.BindingContext, scrollArgs.Group) || scrollArgs.Group == null) && ReferenceEquals(cell.BindingContext, scrollArgs.Item))
						{
							targetHeaderHeight = headerHeight;
							targetHeight = contentHeight;
							found = true;
							break;
						}

						y += contentHeight;
					}
				}
			}
			else
			{
				for (var i = 0; i < templatedItems.Count; i++)
				{
					Cell cell = templatedItems[i] as Cell;

					double height = GetHeight(templateReusables, Control.ItemTemplate, cell);

					if (ReferenceEquals(cell.BindingContext, scrollArgs.Item))
					{
						found = true;
						targetHeight = height;
						break;
					}

					y += height;
				}
			}

			if (!found)
				return;

			ScrollToPosition position = e.Position;
			if (position == ScrollToPosition.MakeVisible)
			{
				if (y >= _viewport.Viewport.Top && y <= _viewport.Viewport.Bottom)
					return;
				if (y > _viewport.Viewport.Bottom)
					position = ScrollToPosition.End;
				else
					position = ScrollToPosition.Start;
			}

			if (position == ScrollToPosition.Start && Element.IsGroupingEnabled)
				y = y - targetHeaderHeight;
			else if (position == ScrollToPosition.Center)
				y = y - (_viewport.ActualHeight / 2 + targetHeight / 2);
			else if (position == ScrollToPosition.End)
				y = y - _viewport.ActualHeight + targetHeight;

			double startY = _viewport.Viewport.Y;
			double distance = y - startY;

			if (e.ShouldAnimate)
			{
				var animation = new Animation(v => { _viewport.SetViewportOrigin(new System.Windows.Point(0, startY + distance * v)); });

				animation.Commit(_animatable, "ScrollTo", length: 500, easing: Easing.CubicInOut);
			}
			else
				_viewport.SetViewportOrigin(new System.Windows.Point(0, y));
		}

		void RestorePreviousSelectedVisual()
		{
			foreach (Tuple<FrameworkElement, SLBinding, Brush> highlight in _previousHighlights)
			{
				if (highlight.Item2 != null)
					highlight.Item1.SetForeground(highlight.Item2);
				else
					highlight.Item1.SetForeground(highlight.Item3);
			}

			_previousHighlights.Clear();
		}

		void SetSelectedVisual(FrameworkElement element)
		{
			IEnumerable<FrameworkElement> highlightMes = FindHighlight(element);
			foreach (FrameworkElement toHighlight in highlightMes)
			{
				Brush brush = null;
				SLBinding binding = toHighlight.GetForegroundBinding();
				if (binding == null)
					brush = toHighlight.GetForeground();

				_previousHighlights.Add(new Tuple<FrameworkElement, SLBinding, Brush>(toHighlight, binding, brush));
				toHighlight.SetForeground((Brush)System.Windows.Application.Current.Resources["PhoneAccentBrush"]);
			}
		}

		void UpdateFooter()
		{
			Control.ListFooter = Controller.FooterElement;
		}

		void UpdateHeader()
		{
			Control.ListHeader = Controller.HeaderElement;
		}

		void UpdateIsRefreshing()
		{
			if (Element.IsRefreshing)
			{
				_progressBar.Visibility = Visibility.Visible;
				_progressBar.IsIndeterminate = true;
			}
			else
			{
				_progressBar.IsIndeterminate = false;
				_progressBar.Visibility = _listBox.IsInPullToRefresh && Element.IsPullToRefreshEnabled && Controller.RefreshAllowed ? Visibility.Visible : Visibility.Collapsed;
			}
		}

		void UpdateJumpList()
		{
			if (_listBox.IsGroupingEnabled && Element.GroupShortNameBinding == null)
				_listBox.JumpListStyle = null;
			else
				_listBox.JumpListStyle = (System.Windows.Style)System.Windows.Application.Current.Resources["HeaderJumpStyle"];
		}
	}
}