- 類型:Mac網(wǎng)絡(luò)工具大。1.2M語(yǔ)言:中文 評(píng)分:10.0
- 標(biāo)簽:
silverlight 提供的控件雖然都好用 但是通常都會(huì)有默認(rèn)模板樣式 有些模板樣式在中國(guó)人看來(lái)肯定不是很好看
所以又時(shí)候 有必要修改下再使用 今天我就遇到DataPager的模板樣式問(wèn)題 我覺(jué)得自帶的不怎么好看
在網(wǎng)上查了下 還沒(méi)有什么好的例子 那我就分享下我自己的例子 大神們見(jiàn)諒哦!
先上圖
感覺(jué)這個(gè)看著換可以吧 你們?nèi)绻每梢宰约涸傩薷南?/p>
首先引入命名空間
xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"
xmlns:vsm="clr-namespace:System.Windows;assembly=System.Windows"
分頁(yè)樣式
<!--測(cè)試分頁(yè)控件樣式開(kāi)始-->
1 <Style x:Key="DataPagerStyle" TargetType="data:DataPager">
2 <Setter Property="Background" Value="#FFF2F3F4"/>
3 <Setter Property="BorderBrush">
4 <Setter.Value>
5 <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
6 <GradientStop Color="#FFA3AEB9" Offset="0"/>
7 <GradientStop Color="#FF8399A9" Offset="0.375"/>
8 <GradientStop Color="#FF718597" Offset="0.375"/>
9 <GradientStop Color="#FF617584" Offset="1"/>
10 </LinearGradientBrush>
11 </Setter.Value>
12 </Setter>
13 <Setter Property="BorderThickness" Value="1"/>
14 <Setter Property="HorizontalContentAlignment" Value="Right" />
15 <Setter Property="NumericButtonStyle">
16 <Setter.Value>
17 <Style TargetType="ToggleButton">
18 <Setter Property="MinHeight" Value="20"/>
19 <Setter Property="MinWidth" Value="20"/>
20 <Setter Property="HorizontalAlignment" Value="Right"/>
21 <Setter Property="VerticalAlignment" Value="Center"/>
22 <Setter Property="Background" Value="#00000000"/>
23 <Setter Property="BorderThickness" Value="1"/>
24 <Setter Property="Padding" Value="1"/>
25 <Setter Property="Template">
26 <Setter.Value>
27 <ControlTemplate TargetType="ToggleButton">
28 <Grid>
29 <vsm:VisualStateManager.VisualStateGroups>
30 <vsm:VisualStateGroup x:Name="CommonStates">
31 <vsm:VisualState x:Name="Normal"/>
32 <vsm:VisualState x:Name="MouseOver">
33 <Storyboard>
34 <ColorAnimation Duration="0" Storyboard.TargetName="OuterBtnBorder" Storyboard.TargetProperty="(BorderBrush).Color" To="#FFFFFFFF"/>
35 <ColorAnimation Duration="0" Storyboard.TargetName="InnerBtnBorder" Storyboard.TargetProperty="(BorderBrush).Color" To="#FFCCD1D6"/>
36 </Storyboard>
37 </vsm:VisualState>
38 <vsm:VisualState x:Name="Pressed">
39 <Storyboard>
40 <ColorAnimation Duration="0" Storyboard.TargetName="OuterBtnBorder" Storyboard.TargetProperty="(BorderBrush).Color" To="#FFFFFFFF"/>
41 <ColorAnimation Duration="0" Storyboard.TargetName="InnerBtnBorder" Storyboard.TargetProperty="(BorderBrush).Color" To="#FFCCD1D6"/>
42 </Storyboard>
43 </vsm:VisualState>
44 <vsm:VisualState x:Name="Disabled">
45 <Storyboard>
46 <DoubleAnimation Duration="0" Storyboard.TargetName="contentPresenter" Storyboard.TargetProperty="Opacity" To="0.5"/>
47 </Storyboard>
48 </vsm:VisualState>
49 </vsm:VisualStateGroup>
50 <vsm:VisualStateGroup x:Name="CheckStates">
51 <vsm:VisualState x:Name="Checked">
52 <Storyboard>
53 <DoubleAnimation Duration="0" Storyboard.TargetName="CheckedStateOuterBorder" Storyboard.TargetProperty="Opacity" To="1"/>
54 </Storyboard>
55 </vsm:VisualState>
56 <vsm:VisualState x:Name="Unchecked"/>
57 </vsm:VisualStateGroup>
58 <vsm:VisualStateGroup x:Name="FocusStates">
59 <vsm:VisualState x:Name="Focused">
60 <Storyboard>
61 <DoubleAnimation Duration="0" Storyboard.TargetName="FocusVisualElement" Storyboard.TargetProperty="Opacity" To="1"/>
62 </Storyboard>
63 </vsm:VisualState>
64 <vsm:VisualState x:Name="Unfocused"/>
65 </vsm:VisualStateGroup>
66 </vsm:VisualStateManager.VisualStateGroups>
67 <Border x:Name="CheckedStateOuterBorder" Background="#7FA9A9A9" BorderBrush="#00FFFFFF" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="3" Opacity="0"/>
68 <Border x:Name="OuterBtnBorder" Background="{TemplateBinding Background}" BorderBrush="#00FFFFFF" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="3">
69 <Border x:Name="InnerBtnBorder" BorderBrush="#00CCD1D6" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="2">
70 <ContentPresenter x:Name="contentPresenter" Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}" HorizontalAlignment="Center" VerticalAlignment="Center" />
71 </Border>
72 </Border>
73 <Border x:Name="FocusVisualElement" Background="{TemplateBinding Background}" BorderBrush="#FF6DBDD1" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="2" Margin="1" Opacity="0"/>
74 </Grid>
75 </ControlTemplate>
76 </Setter.Value>
77 </Setter>
78 </Style>
79 </Setter.Value>
80 </Setter>
81
82 <Setter Property="Template">
83 <Setter.Value>
84 <ControlTemplate TargetType="data:DataPager">
85 <Grid Name="Root" Background="Transparent">
86 <Grid.Resources>
87 <SolidColorBrush x:Key="BackgroundColor" Color="#00000000"/>
88 <SolidColorBrush x:Key="ForegroundColor" Color="#FF000000"/>
89 <SolidColorBrush x:Key="BorderBrushColor" Color="#FFFFFFFF"/>
90 <ControlTemplate x:Key="ButtonTemplate" TargetType="Button">
91 <Grid>
92 <vsm:VisualStateManager.VisualStateGroups>
93 <vsm:VisualStateGroup x:Name="CommonStates">
94 <vsm:VisualState x:Name="Normal"/>
95 <vsm:VisualState x:Name="MouseOver">
96 <Storyboard>
97 <ColorAnimation Duration="0" Storyboard.TargetName="OuterBtnBorder" Storyboard.TargetProperty="(BorderBrush).Color" To="#FFFFFFFF"/>
98 <ColorAnimation Duration="0" Storyboard.TargetName="InnerBtnBorder" Storyboard.TargetProperty="(BorderBrush).Color" To="#FFCCD1D6"/>
99 </Storyboard>
100 </vsm:VisualState>
101 <vsm:VisualState x:Name="Pressed">
102 <Storyboard>
103 <ColorAnimation Duration="0" Storyboard.TargetName="OuterBtnBorder" Storyboard.TargetProperty="(BorderBrush).Color" To="#FFFFFFFF"/>
104 <ColorAnimation Duration="0" Storyboard.TargetName="InnerBtnBorder" Storyboard.TargetProperty="(BorderBrush).Color" To="#00FFFFFF"/>
105 </Storyboard>
106 </vsm:VisualState>
107 <vsm:VisualState x:Name="Disabled">
108 <Storyboard>
109 <DoubleAnimation Duration="0" Storyboard.TargetName="path" Storyboard.TargetProperty="Opacity" To="0.5"/>
110 </Storyboard>
111 </vsm:VisualState>
112 </vsm:VisualStateGroup>
113 <vsm:VisualStateGroup x:Name="FocusStates">
114 <vsm:VisualState x:Name="Focused">
115 <Storyboard>
116 <DoubleAnimation Duration="0" Storyboard.TargetName="FocusVisualElement" Storyboard.TargetProperty="Opacity" To="1"/>
117 </Storyboard>
118 </vsm:VisualState>
119 <vsm:VisualState x:Name="Unfocused"/>
120 </vsm:VisualStateGroup>
121 </vsm:VisualStateManager.VisualStateGroups>
122 <Border x:Name="OuterBtnBorder" BorderBrush="#00FFFFFF" Background="{TemplateBinding Background}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="3">
123 <Border x:Name="InnerBtnBorder" BorderBrush="#00CCD1D6" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="2">
124 <ContentPresenter x:Name="path" Content="{TemplateBinding Content}"/>
125 </Border>
126 </Border>
127 <Border x:Name="FocusVisualElement" BorderBrush="#FF6DBDD1" Background="{TemplateBinding Background}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="2" Margin="1" Opacity="0"/>
128 </Grid>
129 </ControlTemplate>
130
131 <Style x:Key="PagingTextBoxStyle" TargetType="TextBox">
132 <Setter Property="BorderThickness" Value="1"/>
133 <Setter Property="Background" Value="#FFFFFFFF"/>
134 <Setter Property="Foreground" Value="#FF000000"/>
135 <Setter Property="Padding" Value="2, 2, 2, -1"/>
136 <Setter Property="Template">
137 <Setter.Value>
138 <ControlTemplate TargetType="TextBox">
139 <Grid x:Name="RootElement">
140 <vsm:VisualStateManager.VisualStateGroups>
141 <vsm:VisualStateGroup x:Name="CommonStates">
142 <vsm:VisualState x:Name="Normal"/>
143 <vsm:VisualState x:Name="MouseOver">
144 <Storyboard>
145 <ColorAnimation Storyboard.TargetName="MouseOverBorder" Storyboard.TargetProperty="(BorderBrush).Color" To="#FF99C1E2"/>
146 </Storyboard>
147 </vsm:VisualState>
148 <vsm:VisualState x:Name="Disabled">
149 <Storyboard>
150 <DoubleAnimation Storyboard.TargetName="DisabledVisualElement" Storyboard.TargetProperty="Opacity" To="1"/>
151 </Storyboard>
152 </vsm:VisualState>
153 <vsm:VisualState x:Name="ReadOnly">
154 <Storyboard>
155 <DoubleAnimation Storyboard.TargetName="ReadOnlyVisualElement" Storyboard.TargetProperty="Opacity" To="1"/>
156 </Storyboard>
157 </vsm:VisualState>
158 </vsm:VisualStateGroup>
159 <vsm:VisualStateGroup x:Name="FocusStates">
160 <vsm:VisualState x:Name="Focused">
161 <Storyboard>
162 <DoubleAnimation Storyboard.TargetName="FocusVisualElement" Storyboard.TargetProperty="Opacity" To="1"/>
163 </Storyboard>
164 </vsm:VisualState>
165 <vsm:VisualState x:Name="Unfocused"/>
166 </vsm:VisualStateGroup>
167 </vsm:VisualStateManager.VisualStateGroups>
168 <Border x:Name="Border" Opacity="1" Background="#66FFFFFF" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="1">
169 <Grid>
170 <Border x:Name="ReadOnlyVisualElement" Opacity="0" Background="#72F7F7F7"/>
171 <Border x:Name="MouseOverBorder" BorderBrush="Transparent" BorderThickness="1">
172 <ScrollViewer BorderThickness="0" IsTabStop="False" Padding="{TemplateBinding Padding}" x:Name="ContentElement" Margin="0,-3,0,0" VerticalAlignment="Top"/>
173 </Border>
174 </Grid>
175 </Border>
176 <Border x:Name="DisabledVisualElement" IsHitTestVisible="False" Opacity="0" Background="#A5F7F7F7" BorderBrush="#A5F7F7F7" BorderThickness="{TemplateBinding BorderThickness}"/>
177 <Border Margin="1" x:Name="FocusVisualElement" IsHitTestVisible="False" Opacity="0" BorderBrush="#FF6DBDD1" BorderThickness="{TemplateBinding BorderThickness}"/>
178 </Grid>
179 </ControlTemplate>
180 </Setter.Value>
181 </Setter>
182 </Style>
183 </Grid.Resources>
184 <vsm:VisualStateManager.VisualStateGroups>
185
186 <!-- CommonStates -->
187 <vsm:VisualStateGroup x:Name="CommonStates">
188 <vsm:VisualState x:Name="Normal"/>
189 <vsm:VisualState x:Name="Disabled">
190 <Storyboard>
191 <DoubleAnimation Storyboard.TargetName="CurrentPagePrefixTextBlock" Storyboard.TargetProperty="Opacity" To="0.5" Duration="0"/>
192 <DoubleAnimation Storyboard.TargetName="CurrentPageSuffixTextBlock" Storyboard.TargetProperty="Opacity" To="0.5" Duration="0"/>
193 </Storyboard>
194 </vsm:VisualState>
195 </vsm:VisualStateGroup>
196
197 <!-- MoveStates -->
198 <vsm:VisualStateGroup x:Name="MoveStates">
199 <vsm:VisualState x:Name="MoveEnabled">
200 <Storyboard>
201 <ObjectAnimationUsingKeyFrames Storyboard.TargetName="CurrentPageTextBox" Storyboard.TargetProperty="IsEnabled" Duration="0">
202 <DiscreteObjectKeyFrame KeyTime="0" Value="True"/>
203 </ObjectAnimationUsingKeyFrames>
204 </Storyboard>
205 </vsm:VisualState>
206
207 <vsm:VisualState x:Name="MoveDisabled">
208 <Storyboard>
209 <ObjectAnimationUsingKeyFrames Storyboard.TargetName="CurrentPageTextBox" Storyboard.TargetProperty="IsEnabled" Duration="0">
210 <DiscreteObjectKeyFrame KeyTime="0" Value="False"/>
211 </ObjectAnimationUsingKeyFrames>
212 </Storyboard>
213 </vsm:VisualState>
214 </vsm:VisualStateGroup>
215
216 <!-- CanPageFirstStates -->
217 <vsm:VisualStateGroup x:Name="MoveFirstStates">
218 <vsm:VisualState x:Name="MoveFirstEnabled">
219 <Storyboard>
220 <ObjectAnimationUsingKeyFrames Storyboard.TargetName="FirstPageButton" Storyboard.TargetProperty="IsEnabled" Duration="0">
221 <DiscreteObjectKeyFrame KeyTime="0" Value="True"/>
222 </ObjectAnimationUsingKeyFrames>
223 </Storyboard>
224 </vsm:VisualState>
225
226 <vsm:VisualState x:Name="MoveFirstDisabled">
227 <Storyboard>
228 <ObjectAnimationUsingKeyFrames Storyboard.TargetName="FirstPageButton" Storyboard.TargetProperty="IsEnabled" Duration="0">
229 <DiscreteObjectKeyFrame KeyTime="0" Value="False"/>
230 </ObjectAnimationUsingKeyFrames>
231 </Storyboard>
232 </vsm:VisualState>
233 </vsm:VisualStateGroup>
234
235 <!-- CanPagePreviousStates -->
236 <vsm:VisualStateGroup x:Name="MovePreviousStates">
237 <vsm:VisualState x:Name="MovePreviousEnabled">
238 <Storyboard>
239 <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PreviousPageButton" Storyboard.TargetProperty="IsEnabled" Duration="0">
240 <DiscreteObjectKeyFrame KeyTime="0" Value="True"/>
241 </ObjectAnimationUsingKeyFrames>
242 </Storyboard>
243 </vsm:VisualState>
244
245 <vsm:VisualState x:Name="MovePreviousDisabled">
246 <Storyboard>
247 <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PreviousPageButton" Storyboard.TargetProperty="IsEnabled" Duration="0">
248 <DiscreteObjectKeyFrame KeyTime="0" Value="False"/>
249 </ObjectAnimationUsingKeyFrames>
250 </Storyboard>
251 </vsm:VisualState>
252 </vsm:VisualStateGroup>
253
254 <!-- CanPageNextStates -->
255 <vsm:VisualStateGroup x:Name="MoveNextStates">
256 <vsm:VisualState x:Name="MoveNextEnabled">
257 <Storyboard>
258 <ObjectAnimationUsingKeyFrames Storyboard.TargetName="NextPageButton" Storyboard.TargetProperty="IsEnabled" Duration="0">
259 <DiscreteObjectKeyFrame KeyTime="0" Value="True"/>
260 </ObjectAnimationUsingKeyFrames>
261 </Storyboard>
262 </vsm:VisualState>
263
264 <vsm:VisualState x:Name="MoveNextDisabled">
265 <Storyboard>
266 <ObjectAnimationUsingKeyFrames Storyboard.TargetName="NextPageButton" Storyboard.TargetProperty="IsEnabled" Duration="0">
267 <DiscreteObjectKeyFrame KeyTime="0" Value="False"/>
268 </ObjectAnimationUsingKeyFrames>
269 </Storyboard>
270 </vsm:VisualState>
271 </vsm:VisualStateGroup>
272
273 <!-- CanPageLastStates -->
274 <vsm:VisualStateGroup x:Name="MoveLastStates">
275 <vsm:VisualState x:Name="MoveLastEnabled">
276 <Storyboard>
277 <ObjectAnimationUsingKeyFrames Storyboard.TargetName="LastPageButton" Storyboard.TargetProperty="IsEnabled" Duration="0">
278 <DiscreteObjectKeyFrame KeyTime="0" Value="True"/>
279 </ObjectAnimationUsingKeyFrames>
280 </Storyboard>
281 </vsm:VisualState>
282
283 <vsm:VisualState x:Name="MoveLastDisabled">
284 <Storyboard>
285 <ObjectAnimationUsingKeyFrames Storyboard.TargetName="LastPageButton" Storyboard.TargetProperty="IsEnabled" Duration="0">
286 <DiscreteObjectKeyFrame KeyTime="0" Value="False"/>
287 </ObjectAnimationUsingKeyFrames>
288 </Storyboard>
289 </vsm:VisualState>
290 </vsm:VisualStateGroup>
291
292 <!-- PagerDisplayModeStates -->
293 <vsm:VisualStateGroup x:Name="DisplayModeStates">
294 <vsm:VisualState x:Name="FirstLastNumeric">
295 <Storyboard>
296 <ObjectAnimationUsingKeyFrames Storyboard.TargetName="NextPageButton" Storyboard.TargetProperty="Visibility">
297 <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
298 </ObjectAnimationUsingKeyFrames>
299 <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PreviousPageButton" Storyboard.TargetProperty="Visibility">
300 <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
301 </ObjectAnimationUsingKeyFrames>
302 <ObjectAnimationUsingKeyFrames Storyboard.TargetName="CurrentPageTextBox" Storyboard.TargetProperty="Visibility">
303 <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
304 </ObjectAnimationUsingKeyFrames>
305 <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PageDisplay" Storyboard.TargetProperty="Visibility">
306 <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
307 </ObjectAnimationUsingKeyFrames>
308 </Storyboard>
309 </vsm:VisualState>
310
311 <vsm:VisualState x:Name="FirstLastPreviousNext">
312 <Storyboard>
313 <ObjectAnimationUsingKeyFrames Storyboard.TargetName="NumericButtonPanel" Storyboard.TargetProperty="Visibility">
314 <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
315 </ObjectAnimationUsingKeyFrames>
316 </Storyboard>
317 </vsm:VisualState>
318
319 <vsm:VisualState x:Name="FirstLastPreviousNextNumeric">
320 <Storyboard>
321 <ObjectAnimationUsingKeyFrames Storyboard.TargetName="CurrentPageTextBox" Storyboard.TargetProperty="Visibility">
322 <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
323 </ObjectAnimationUsingKeyFrames>
324 <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PageDisplay" Storyboard.TargetProperty="Visibility">
325 <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
326 </ObjectAnimationUsingKeyFrames>
327 </Storyboard>
328 </vsm:VisualState>
329
330 <vsm:VisualState x:Name="Numeric">
331 <Storyboard>
332 <ObjectAnimationUsingKeyFrames Storyboard.TargetName="FirstPageButton" Storyboard.TargetProperty="Visibility">
333 <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
334 </ObjectAnimationUsingKeyFrames>
335 <ObjectAnimationUsingKeyFrames Storyboard.TargetName="LastPageButton" Storyboard.TargetProperty="Visibility">
336 <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
337 </ObjectAnimationUsingKeyFrames>
338 <ObjectAnimationUsingKeyFrames Storyboard.TargetName="NextPageButton" Storyboard.TargetProperty="Visibility">
339 <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
340 </ObjectAnimationUsingKeyFrames>
341 <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PreviousPageButton" Storyboard.TargetProperty="Visibility">
342 <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
343 </ObjectAnimationUsingKeyFrames>
344 <ObjectAnimationUsingKeyFrames Storyboard.TargetName="CurrentPageTextBox" Storyboard.TargetProperty="Visibility">
345 <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
346 </ObjectAnimationUsingKeyFrames>
347 <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PageDisplay" Storyboard.TargetProperty="Visibility">
348 <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
349 </ObjectAnimationUsingKeyFrames>
350 <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Separator1" Storyboard.TargetProperty="Visibility">
351 <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
352 </ObjectAnimationUsingKeyFrames>
353 <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Separator2" Storyboard.TargetProperty="Visibility">
354 <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
355 </ObjectAnimationUsingKeyFrames>
356 </Storyboard>
357 </vsm:VisualState>
358
359 <vsm:VisualState x:Name="PreviousNext">
360 <Storyboard>
361 <ObjectAnimationUsingKeyFrames Storyboard.TargetName="FirstPageButton" Storyboard.TargetProperty="Visibility">
362 <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
363 </ObjectAnimationUsingKeyFrames>
364 <ObjectAnimationUsingKeyFrames Storyboard.TargetName="LastPageButton" Storyboard.TargetProperty="Visibility">
365 <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
366 </ObjectAnimationUsingKeyFrames>
367 <ObjectAnimationUsingKeyFrames Storyboard.TargetName="NumericButtonPanel" Storyboard.TargetProperty="Visibility">
368 <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
369 </ObjectAnimationUsingKeyFrames>
370 </Storyboard>
371 </vsm:VisualState>
372
373 <vsm:VisualState x:Name="PreviousNextNumeric">
374 <Storyboard>
375 <ObjectAnimationUsingKeyFrames Storyboard.TargetName="FirstPageButton" Storyboard.TargetProperty="Visibility">
376 <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
377 </ObjectAnimationUsingKeyFrames>
378 <ObjectAnimationUsingKeyFrames Storyboard.TargetName="LastPageButton" Storyboard.TargetProperty="Visibility">
379 <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
380 </ObjectAnimationUsingKeyFrames>
381 <ObjectAnimationUsingKeyFrames Storyboard.TargetName="CurrentPageTextBox" Storyboard.TargetProperty="Visibility">
382 <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
383 </ObjectAnimationUsingKeyFrames>
384 <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PageDisplay" Storyboard.TargetProperty="Visibility">
385 <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
386 </ObjectAnimationUsingKeyFrames>
387 </Storyboard>
388 </vsm:VisualState>
389 </vsm:VisualStateGroup>
390
391 </vsm:VisualStateManager.VisualStateGroups>
392
393 <!-- DataPager Control Parts -->
394 <Border MinHeight="24" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Padding}" VerticalAlignment="Bottom" CornerRadius="2">
395 <StackPanel Orientation="Horizontal" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="Stretch">
396 <!--FirstPage Button -->
397 <Button x:Name="FirstPageButton" Content="首頁(yè)" Height="20" Width="30" Background="{StaticResource BackgroundColor}" Foreground="{StaticResource ForegroundColor}" BorderBrush="{StaticResource BorderBrushColor}" BorderThickness="1" Padding="1" HorizontalAlignment="Right" VerticalAlignment="Center" HorizontalContentAlignment="Center" Template="{StaticResource ButtonTemplate}">
398 <!--<Button.Content>
399 <Grid Height="9" Width="8" >
400 <Path Stretch="Fill" Data="M0,1 L1,0 L1,2 Z" Width="5" Height="9" HorizontalAlignment="Right" Fill="{TemplateBinding Foreground}"/>
401 <Rectangle Width="2" HorizontalAlignment="Left" Fill="{TemplateBinding Foreground}"/>
402 </Grid>
403 </Button.Content>
404 -->
405 </Button>
406
407
408 <!--PreviousPage Button-->
409 <Button Name="PreviousPageButton" Content="上一頁(yè)" Height="20" Width="40" Background="{StaticResource BackgroundColor}" Foreground="{StaticResource ForegroundColor}" BorderBrush="{StaticResource BorderBrushColor}" BorderThickness="1" Padding="1" HorizontalAlignment="Right" VerticalAlignment="Center" Template="{StaticResource ButtonTemplate}">
410 <!--<Button.Content>
411 <Path Stretch="Fill" Data="M0,1 L1,0 L1,2 Z" Width="5" Height="9" HorizontalAlignment="Center" Fill="{TemplateBinding Foreground}"/>
412 </Button.Content>-->
413 </Button>
414
415 <Border x:Name="Separator1" Width="1" Background="#FFCCD1D6" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="1,0,1,0" Margin="0,3,0,3"/>
416 <!--Numeric Button Panel-->
417 <StackPanel x:Name="NumericButtonPanel" Orientation="Horizontal" Margin="1"/>
418
419 <!--Page Display-->
420 <StackPanel x:Name="PageDisplay" Orientation="Horizontal">
421 <TextBlock x:Name="CurrentPagePrefixTextBlock" Width="Auto" VerticalAlignment="Center" Margin="4,0,0,0" Foreground="{TemplateBinding Foreground}"/>
422 <TextBox x:Name="CurrentPageTextBox" TextWrapping="Wrap" Width="40" Height="Auto" VerticalAlignment="Center" Margin="4,2,4,2" Style="{StaticResource PagingTextBoxStyle}" Foreground="{TemplateBinding Foreground}" BorderBrush="{TemplateBinding BorderBrush}"/>
423 <TextBlock x:Name="CurrentPageSuffixTextBlock" Width="Auto" VerticalAlignment="Center" Margin="0,0,4,0" Foreground="{TemplateBinding Foreground}"/>
424 </StackPanel>
425 <Border x:Name="Separator2" Width="1" Background="#FFCCD1D6" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="1,0,1,0" Margin="0,3,0,3"/>
426
427 <!--NextPage Button-->
428 <Button x:Name="NextPageButton" Content="下一頁(yè)" Height="20" Width="40" Background="{StaticResource BackgroundColor}" Foreground="{StaticResource ForegroundColor}" BorderBrush="{StaticResource BorderBrushColor}" BorderThickness="1" Padding="1" HorizontalAlignment="Right" VerticalAlignment="Center" Template="{StaticResource ButtonTemplate}">
429 <!--<Button.Content>
430 <Path Stretch="Fill" Data="M0,0 L1,1 L0,2 Z" Width="5" Height="9" HorizontalAlignment="Center" Fill="{TemplateBinding Foreground}"/>
431 </Button.Content>-->
432 </Button>
433
434 <!--LastPage Button-->
435 <Button x:Name="LastPageButton" Content="尾頁(yè)" Height="20" Width="30" Background="{StaticResource BackgroundColor}" Foreground="{StaticResource ForegroundColor}" BorderBrush="{StaticResource BorderBrushColor}" BorderThickness="1" Padding="1" HorizontalAlignment="Right" VerticalAlignment="Center" Template="{StaticResource ButtonTemplate}">
436 <!--<Button.Content>
437 <Grid Height="9" Width="8">
438 <Path Stretch="Fill" Data="M0,0 L1,1 L0,2 Z" Width="5" Height="9" HorizontalAlignment="Left" Fill="{TemplateBinding Foreground}"/>
439 <Rectangle Width="2" HorizontalAlignment="Right" Fill="{TemplateBinding Foreground}"/>
440 </Grid>
441 </Button.Content>-->
442 </Button>
443 </StackPanel>
444 </Border>
445 </Grid>
446 </ControlTemplate>
447 </Setter.Value>
448 </Setter>
449 </Style>
<!--分頁(yè)控件結(jié)束-->
調(diào)用
<data:DataPager x:Name ="PagerBar" DisplayMode="FirstLastPreviousNextNumeric" VerticalAlignment="Bottom" Style="{StaticResource DataPagerStyle}"
HorizontalAlignment="Center" Source="{Binding}" NumericButtonCount="4" AutoEllipsis="True" Canvas.Top="402" Canvas.Left="116" />
最后給大家給出我自己寫(xiě)的分頁(yè)后臺(tái)代碼 后臺(tái)每次只取一頁(yè)例子
1 public partial class WinFriendPanel : ChildWindow
2 {
3 private const int PageSize = 1;//頁(yè)大小
4 private List<int> itemCount = new List<int>();//總記錄
5 private bool flag = true;//首次加載標(biāo)志
6
7 public WinFriendPanel()
8 {
9 InitializeComponent();
10 InitializeControls();
11 }
12
13 /// <summary>
14 /// 初始化控件
15 /// </summary>
16 private void InitializeControls()
17 {
18 this.Name = "playerFriend";
19 //點(diǎn)擊頁(yè)碼的事件,獲取當(dāng)前頁(yè)的數(shù)據(jù)并綁定到DataGrid
20 this.PagerBar.PageIndexChanged += (s, e) =>
21 {
22 if (!flag)//如果不是首次加載
23 {
24 ClientMessagePool.AddSendMessage(ClientCommand.GetPlayerFriend(GameGlobal.CurrentUser.Player.playerId.ToString(), ((DataPager)s).PageIndex + 1, PageSize));
25 }
26 flag = false;
27 };
28 //默認(rèn)第一頁(yè)數(shù)據(jù)
29 ClientMessagePool.AddSendMessage(ClientCommand.GetPlayerFriend(GameGlobal.CurrentUser.Player.playerId.ToString(), 1, PageSize));
30 }
31
32 /// <summary>
33 /// 顯示玩家好友列表
34 /// </summary>
35 /// <param name="current">好友列表</param>
36 public void DisplayPlayerFriends(List<PlayerFriendPage> current)
37 {
38 if (current != null)
39 {
40 if (flag)//如果首次加載
41 {
42 int totalpagers = current[0] != null ? current[0].recordCount : 0;//總記錄數(shù)
43 for (int i = 1; i <= totalpagers; i++)
44 itemCount.Add(i);
45 PagedCollectionView pcv = new PagedCollectionView(itemCount);
46 pcv.PageSize = PageSize;
47 this.PagerBar.Source = pcv; //這兒會(huì)自動(dòng)觸發(fā)this.dataPager1.PageIndexChanged事件
48 }
49 PagedCollectionView view = new PagedCollectionView(current);
50 this.GridListData.ItemsSource = view;
51 }
52 }
53
54 }