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