markus / KCOM / Controls / PageNavigator.xaml.cs @ 0cda2a88
이력 | 보기 | 이력해설 | 다운로드 (6.33 KB)
1 |
using KCOM.Common; |
---|---|
2 |
using KCOMDataModel.DataModel; |
3 |
using System; |
4 |
using System.Collections.Generic; |
5 |
using System.Collections.ObjectModel; |
6 |
using System.ComponentModel; |
7 |
using System.Linq; |
8 |
using System.Text; |
9 |
using System.Windows; |
10 |
using System.Windows.Controls; |
11 |
using System.Windows.Data; |
12 |
using System.Windows.Documents; |
13 |
using System.Windows.Input; |
14 |
using System.Windows.Media; |
15 |
using System.Windows.Media.Imaging; |
16 |
using System.Windows.Navigation; |
17 |
using System.Windows.Shapes; |
18 |
|
19 |
namespace KCOM.Controls |
20 |
{ |
21 |
/// <summary> |
22 |
/// Interaction logic for PageNavigator.xaml |
23 |
/// </summary> |
24 |
public partial class PageNavigator : UserControl, INotifyPropertyChanged |
25 |
{ |
26 |
public List<FAVORITE_DOC> _FavoriteSet { get; set; } |
27 |
public event PropertyChangedEventHandler PropertyChanged; |
28 |
public PageNavigator() |
29 |
{ |
30 |
InitializeComponent(); |
31 |
_Initialize = true; |
32 |
} |
33 |
public ObservableCollection<ThumbnailItem> _thumbnailItems; |
34 |
private List<DOCPAGE> _PageList = null; |
35 |
private string _DefaultUri = null; |
36 |
public ThumbnailItem CurrentPage = null; |
37 |
public ThumbnailItem _NextPage = null; |
38 |
|
39 |
private bool _Initialize; |
40 |
public event EventHandler<PageChangeEventArgs> PageChanged; |
41 |
public event EventHandler<PageChangeEventArgs> PageChanging; |
42 |
|
43 |
public class PageChangeEventArgs : EventArgs |
44 |
{ |
45 |
public DOCPAGE CurrentPage { get; set; } |
46 |
public string PageUri { get; set; } |
47 |
public int PageNumber { get; set; } |
48 |
} |
49 |
|
50 |
private bool _IsFitOn { get; set; } |
51 |
public bool IsFitOn |
52 |
{ |
53 |
get |
54 |
{ |
55 |
return _IsFitOn; |
56 |
} |
57 |
set |
58 |
{ |
59 |
_IsFitOn = value; |
60 |
RaisePropertyChanged("IsFitOn"); |
61 |
} |
62 |
} |
63 |
|
64 |
public void RaisePropertyChanged(string propName) |
65 |
{ |
66 |
if (PropertyChanged != null) |
67 |
PropertyChanged(this, new PropertyChangedEventArgs(propName)); |
68 |
} |
69 |
|
70 |
public void SetPageNavi(List<DOCPAGE> PageList, string DefaultUri) |
71 |
{ |
72 |
this._PageList = PageList; |
73 |
this._DefaultUri = DefaultUri; |
74 |
ThumbnailSet(); |
75 |
} |
76 |
private void ImgListbox_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e) |
77 |
{ |
78 |
//tmStart = false; |
79 |
//tm.Stop(); |
80 |
//tm.Tick -= new EventHandler(tm_Tick); |
81 |
|
82 |
System.Threading.Tasks.Task.Factory.StartNew(() => |
83 |
{ |
84 |
|
85 |
int _PageNo = -1; |
86 |
|
87 |
if (this.CurrentPage != null) |
88 |
{ |
89 |
_PageNo = this.CurrentPage.PageNumber; |
90 |
}; |
91 |
|
92 |
if (_PageNo != (ImgListbox.SelectedItem as ThumbnailItem).PageNumber) |
93 |
{ |
94 |
GotoPage((ImgListbox.SelectedItem as ThumbnailItem).PageNumber); |
95 |
} |
96 |
|
97 |
}).RunAndForget(); |
98 |
} |
99 |
|
100 |
public bool GotoPageFlag = false; |
101 |
|
102 |
public void GotoPage(int _pageNumber) |
103 |
{ |
104 |
int _PageNo = -1; |
105 |
if (int.TryParse(_pageNumber.ToString(), out _PageNo)) |
106 |
{ |
107 |
var _page = _thumbnailItems.Where(item => item.PageNumber == _PageNo); |
108 |
if (_page.Count() > 0) |
109 |
{ |
110 |
ThumbnailItem _item = _page.First(); |
111 |
setPageChange(_item); |
112 |
} |
113 |
} |
114 |
} |
115 |
|
116 |
private void setPageChange(ThumbnailItem thumbnailItem) |
117 |
{ |
118 |
if (thumbnailItem != null) |
119 |
{ |
120 |
if (PageChanging != null) |
121 |
{ |
122 |
CurrentPage = _NextPage; |
123 |
_NextPage = thumbnailItem; |
124 |
PageChanging(this, new PageChangeEventArgs |
125 |
{ |
126 |
CurrentPage = _PageList.Where(p => p.PAGE_NUMBER == thumbnailItem.PageNumber).First(), |
127 |
PageNumber = Convert.ToInt32(thumbnailItem.PageNumber), |
128 |
PageUri = null |
129 |
}); |
130 |
|
131 |
} |
132 |
} |
133 |
} |
134 |
|
135 |
private void Grid_LeftButtonDown(object sender, MouseButtonEventArgs e) |
136 |
{ |
137 |
|
138 |
} |
139 |
private void ThumbnailSet() |
140 |
{ |
141 |
if (!_Initialize) return; |
142 |
|
143 |
this._thumbnailItems = new ObservableCollection<ThumbnailItem>(); |
144 |
|
145 |
var uri = _DefaultUri.Replace("{0}/{1}_{2}", "8/0_0"); |
146 |
this._PageList = this._PageList.OrderBy(data => data.PAGE_NUMBER).ToList(); |
147 |
this._PageList.ForEach(page => |
148 |
{ |
149 |
var _pageNo = page.PAGE_NUMBER; |
150 |
|
151 |
this._thumbnailItems.Add(new ThumbnailItem |
152 |
{ |
153 |
ImageUri = new Uri(uri.Replace("{PageNo}", _pageNo.ToString())), |
154 |
PageNumber = Convert.ToInt32(_pageNo), |
155 |
Angle = Convert.ToInt32(page.PAGE_ANGLE), |
156 |
}); |
157 |
}); |
158 |
|
159 |
txtTotPageNo.Text = this._PageList.Count().ToString(); |
160 |
|
161 |
txtThumbCount.Text = String.Format("Count : {0}", (this._thumbnailItems.Count).ToString()); |
162 |
|
163 |
if (ImgListbox.ItemsSource == null) |
164 |
{ |
165 |
ImgListbox.ItemsSource = this._thumbnailItems; |
166 |
|
167 |
|
168 |
if (ImgListbox.Items.Count > 0) |
169 |
{ |
170 |
//int StartPageIdx = Convert.ToInt32(App.ViewInfo.StartPage) - 1; |
171 |
int StartPageIdx = 1; |
172 |
//if (App.ViewInfo.IsCustomPage) |
173 |
//{ |
174 |
// ImgListbox.SelectedItem = ImgListbox.Items.Where(data => (data as ThumbnailItem).PageNumber == Convert.ToInt32(App.ViewInfo.StartPage)).FirstOrDefault(); |
175 |
//} |
176 |
//else |
177 |
//{ |
178 |
|
179 |
if (StartPageIdx <= 0 || StartPageIdx > ImgListbox.Items.Count || StartPageIdx == 1) |
180 |
{ |
181 |
ImgListbox.SelectedItem = ImgListbox.Items[0]; |
182 |
} |
183 |
else |
184 |
{ |
185 |
ImgListbox.SelectedItem = ImgListbox.Items[StartPageIdx]; |
186 |
} |
187 |
//} |
188 |
} |
189 |
} |
190 |
else |
191 |
{ |
192 |
ImgListbox.UpdateLayout(); |
193 |
ImgListbox.ItemsSource = this._thumbnailItems; |
194 |
} |
195 |
} |
196 |
} |
197 |
} |