markus / KCOM / Controls / PageNavigator.xaml.cs @ 2c3eae15
이력 | 보기 | 이력해설 | 다운로드 (6.18 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 |
int _PageNo = -1; |
82 |
|
83 |
if (this.CurrentPage != null) |
84 |
{ |
85 |
_PageNo = this.CurrentPage.PageNumber; |
86 |
}; |
87 |
|
88 |
if (_PageNo != (ImgListbox.SelectedItem as ThumbnailItem).PageNumber) |
89 |
{ |
90 |
GotoPage((ImgListbox.SelectedItem as ThumbnailItem).PageNumber); |
91 |
} |
92 |
} |
93 |
|
94 |
public bool GotoPageFlag = false; |
95 |
|
96 |
public void GotoPage(int _pageNumber) |
97 |
{ |
98 |
int _PageNo = -1; |
99 |
if (int.TryParse(_pageNumber.ToString(), out _PageNo)) |
100 |
{ |
101 |
var _page = _thumbnailItems.Where(item => item.PageNumber == _PageNo); |
102 |
if (_page.Count() > 0) |
103 |
{ |
104 |
ThumbnailItem _item = _page.First(); |
105 |
setPageChange(_item); |
106 |
} |
107 |
} |
108 |
} |
109 |
|
110 |
private void setPageChange(ThumbnailItem thumbnailItem) |
111 |
{ |
112 |
if (thumbnailItem != null) |
113 |
{ |
114 |
if (PageChanging != null) |
115 |
{ |
116 |
CurrentPage = _NextPage; |
117 |
_NextPage = thumbnailItem; |
118 |
PageChanging(this, new PageChangeEventArgs |
119 |
{ |
120 |
CurrentPage = _PageList.Where(p => p.PAGE_NUMBER == thumbnailItem.PageNumber).First(), |
121 |
PageNumber = Convert.ToInt32(thumbnailItem.PageNumber), |
122 |
PageUri = null |
123 |
}); |
124 |
|
125 |
} |
126 |
} |
127 |
} |
128 |
|
129 |
private void Grid_LeftButtonDown(object sender, MouseButtonEventArgs e) |
130 |
{ |
131 |
|
132 |
} |
133 |
private void ThumbnailSet() |
134 |
{ |
135 |
if (!_Initialize) return; |
136 |
|
137 |
this._thumbnailItems = new ObservableCollection<ThumbnailItem>(); |
138 |
|
139 |
var uri = _DefaultUri.Replace("{0}/{1}_{2}", "8/0_0"); |
140 |
this._PageList = this._PageList.OrderBy(data => data.PAGE_NUMBER).ToList(); |
141 |
this._PageList.ForEach(page => |
142 |
{ |
143 |
var _pageNo = page.PAGE_NUMBER; |
144 |
|
145 |
this._thumbnailItems.Add(new ThumbnailItem |
146 |
{ |
147 |
ImageUri = new Uri(uri.Replace("{PageNo}", _pageNo.ToString())), |
148 |
PageNumber = Convert.ToInt32(_pageNo), |
149 |
Angle = Convert.ToInt32(page.PAGE_ANGLE), |
150 |
}); |
151 |
}); |
152 |
|
153 |
txtTotPageNo.Text = this._PageList.Count().ToString(); |
154 |
|
155 |
txtThumbCount.Text = String.Format("Count : {0}", (this._thumbnailItems.Count).ToString()); |
156 |
|
157 |
if (ImgListbox.ItemsSource == null) |
158 |
{ |
159 |
ImgListbox.ItemsSource = this._thumbnailItems; |
160 |
|
161 |
|
162 |
if (ImgListbox.Items.Count > 0) |
163 |
{ |
164 |
//int StartPageIdx = Convert.ToInt32(App.ViewInfo.StartPage) - 1; |
165 |
int StartPageIdx = 1; |
166 |
//if (App.ViewInfo.IsCustomPage) |
167 |
//{ |
168 |
// ImgListbox.SelectedItem = ImgListbox.Items.Where(data => (data as ThumbnailItem).PageNumber == Convert.ToInt32(App.ViewInfo.StartPage)).FirstOrDefault(); |
169 |
//} |
170 |
//else |
171 |
//{ |
172 |
|
173 |
if (StartPageIdx <= 0 || StartPageIdx > ImgListbox.Items.Count || StartPageIdx == 1) |
174 |
{ |
175 |
ImgListbox.SelectedItem = ImgListbox.Items[0]; |
176 |
} |
177 |
else |
178 |
{ |
179 |
ImgListbox.SelectedItem = ImgListbox.Items[StartPageIdx]; |
180 |
} |
181 |
//} |
182 |
} |
183 |
} |
184 |
else |
185 |
{ |
186 |
ImgListbox.UpdateLayout(); |
187 |
ImgListbox.ItemsSource = this._thumbnailItems; |
188 |
} |
189 |
} |
190 |
} |
191 |
} |