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
|
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.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Tango.BL.Entities;
using Tango.Touch.Components;
using Tango.Touch.Controls;
namespace Tango.PPC.Common.Controls
{
/// <summary>
/// Represents the twin color catalog control.
/// </summary>
/// <seealso cref="System.Windows.Controls.UserControl" />
/// <seealso cref="System.Windows.Markup.IComponentConnector" />
public partial class TwineCatalogControl : UserControl
{
private ColorCatalog _catalog;
private bool _preventChange;
private double _lastScrollPosition = 0;
private bool _findInProcess = false;
/// <summary>
/// Gets or sets the selected catalog item.
/// </summary>
public ColorCatalogsItem SelectedItem
{
get { return (ColorCatalogsItem)GetValue(SelectedItemProperty); }
set { SetValue(SelectedItemProperty, value); }
}
public static readonly DependencyProperty SelectedItemProperty =
DependencyProperty.Register("SelectedItem", typeof(ColorCatalogsItem), typeof(TwineCatalogControl), new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, new PropertyChangedCallback(OnSelectedItemPropertyChanged)));
private static void OnSelectedItemPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
TwineCatalogControl twineCatalogControl = (TwineCatalogControl)d;
if(e.OldValue != e.NewValue)
{
twineCatalogControl.SelectedItemPropertyChanged();
}
}
/// <summary>
/// Gets or sets the collection filter.
/// </summary>
public ICollectionFilter CollectionFilter
{
get { return (ICollectionFilter)GetValue(CollectionFilterProperty); }
set { SetValue(CollectionFilterProperty, value); }
}
public static readonly DependencyProperty CollectionFilterProperty =
DependencyProperty.Register("CollectionFilter", typeof(ICollectionFilter), typeof(TwineCatalogControl), new PropertyMetadata(null, (d, e) => (d as TwineCatalogControl).OnCollectionFilterChanged()));
public void SelectedItemPropertyChanged()
{
// if(renderer.SelectedItem != this.SelectedItem)
// renderer.SelectedItem = this.SelectedItem;
}
/// <summary>
/// Initializes a new instance of the <see cref="TwineCatalogControl"/> class.
/// </summary>
public TwineCatalogControl()
{
InitializeComponent();
//list.ApplyTemplate();
//list.Loaded += TwineCatalogControl_Loaded;
DataContextChanged += (x, y) =>
{
_catalog = DataContext as ColorCatalog;
if (scrollViewer != null && _catalog != null)
{
scrollViewer.ScrollToTop();
_preventChange = true;
slider.Value = _catalog.ColorCatalogsGroupsOrdered.Count;
_preventChange = false;
}
};
scrollViewer.Scrolling += ScrollViewer_Scrolling;
}
/// <summary>
/// Handles the Scrolling event of the ScrollViewer control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="Touch.Controls.DoubleValueChangedEventArgs"/> instance containing the event data.</param>
private void ScrollViewer_Scrolling(object sender, Touch.Controls.DoubleValueChangedEventArgs e)
{
if (!_preventChange)
{
if (e.Value > _lastScrollPosition + 60 || e.Value < _lastScrollPosition - 60)
{
var group = renderer.GetVisibleGroup();
if (group != null)
{
_preventChange = true;
slider.Value = slider.Maximum - _catalog.ColorCatalogsGroupsOrdered.IndexOf(group);
_preventChange = false;
}
_lastScrollPosition = e.Value;
}
}
}
/// <summary>
/// Handles the ValueChanged event of the TouchSlider control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="RoutedPropertyChangedEventArgs{System.Double}"/> instance containing the event data.</param>
private void TouchSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
if (_catalog == null || _catalog.ColorCatalogsGroupsOrdered.Count == 0) return;
if (!_preventChange)
{
if (_catalog != null && scrollViewer != null)
{
_preventChange = true;
var group = _catalog.ColorCatalogsGroupsOrdered.ElementAt(_catalog.ColorCatalogsGroupsOrdered.Count - 1 - (int)e.NewValue);
scrollViewer.ScrollToPosition(renderer.GetGroupPosition(group));
_preventChange = false;
}
}
if (_catalog != null && _catalog.ColorCatalogsGroupsOrdered.Count > _catalog.ColorCatalogsGroupsOrdered.Count - 1 - (int)e.NewValue && _catalog.ColorCatalogsGroupsOrdered.Count - 1 - (int)e.NewValue > -1)
{
slider.Foreground = new SolidColorBrush(_catalog.ColorCatalogsGroupsOrdered.ElementAt(_catalog.ColorCatalogsGroupsOrdered.Count - 1 - (int)e.NewValue).Color);
}
}
private void OnCollectionFilterChanged()
{
if (_findInProcess)
return;
if (CollectionFilter != null)
{
CollectionFilter.FilterChanged -= CollectionFilter_FilterChanged;
CollectionFilter.FilterChanged += CollectionFilter_FilterChanged;
}
}
private void CollectionFilter_FilterChanged(object sender, EventArgs e)
{
_findInProcess = true;
if (CollectionFilter != null )
{
renderer.ScrollToFirstFindItem(CollectionFilter);
}
_findInProcess = false;
}
}
}
|