Silverlight完全自定义DataPager-程序员宅基地

silverlight 提供的控件虽然都好用 但是通常都会有默认模板样式 有些模板样式在中国人看来肯定不是很好看

所以又时候 有必要修改下再使用 今天我就遇到DataPager的模板样式问题 我觉得自带的不怎么好看

在网上查了下 还没有什么好的例子 那我就分享下我自己的例子 大神们见谅哦!

 

先上图

感觉这个看着换可以吧 你们如果要用可以自己再修改下

 

首先引入命名空间

          xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"
           xmlns:vsm="clr-namespace:System.Windows;assembly=System.Windows"

 

分页样式

 

        <!--测试分页控件样式开始-->

  

View Code
  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="首页" 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="上一页" 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="下一页" 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="尾页" 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>

 

        <!--分页控件结束-->

 

 

 调用


 <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" />

 

最后给大家给出我自己写的分页后台代码 后台每次只取一页例子

 1 public partial class WinFriendPanel : ChildWindow
 2     {
 3         private const int PageSize = 1;//页大小
 4         private List<int> itemCount = new List<int>();//总记录
 5         private bool flag = true;//首次加载标志
 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             //点击页码的事件,获取当前页的数据并绑定到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             //默认第一页数据
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;//总记录数
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; //这儿会自动触发this.dataPager1.PageIndexChanged事件
48                 }
49                 PagedCollectionView view = new PagedCollectionView(current);
50                 this.GridListData.ItemsSource = view;
51             }
52         }
53        
54     }

 

 

转载于:https://www.cnblogs.com/LYunF/archive/2012/12/05/2802621.html

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/weixin_30448685/article/details/97718777

智能推荐

874计算机科学基础综合,2018年四川大学874计算机科学专业基础综合之计算机操作系统考研仿真模拟五套题...-程序员宅基地

文章浏览阅读1.1k次。一、选择题1. 串行接口是指( )。A. 接口与系统总线之间串行传送,接口与I/0设备之间串行传送B. 接口与系统总线之间串行传送,接口与1/0设备之间并行传送C. 接口与系统总线之间并行传送,接口与I/0设备之间串行传送D. 接口与系统总线之间并行传送,接口与I/0设备之间并行传送【答案】C2. 最容易造成很多小碎片的可变分区分配算法是( )。A. 首次适应算法B. 最佳适应算法..._874 计算机科学专业基础综合题型

XShell连接失败:Could not connect to '192.168.191.128' (port 22): Connection failed._could not connect to '192.168.17.128' (port 22): c-程序员宅基地

文章浏览阅读9.7k次,点赞5次,收藏15次。连接xshell失败,报错如下图,怎么解决呢。1、通过ps -e|grep ssh命令判断是否安装ssh服务2、如果只有客户端安装了,服务器没有安装,则需要安装ssh服务器,命令:apt-get install openssh-server3、安装成功之后,启动ssh服务,命令:/etc/init.d/ssh start4、通过ps -e|grep ssh命令再次判断是否正确启动..._could not connect to '192.168.17.128' (port 22): connection failed.

杰理之KeyPage【篇】_杰理 空白芯片 烧入key文件-程序员宅基地

文章浏览阅读209次。00000000_杰理 空白芯片 烧入key文件

一文读懂ChatGPT,满足你对chatGPT的好奇心_引发对chatgpt兴趣的表述-程序员宅基地

文章浏览阅读475次。2023年初,“ChatGPT”一词在社交媒体上引起了热议,人们纷纷探讨它的本质和对社会的影响。就连央视新闻也对此进行了报道。作为新传专业的前沿人士,我们当然不能忽视这一热点。本文将全面解析ChatGPT,打开“技术黑箱”,探讨它对新闻与传播领域的影响。_引发对chatgpt兴趣的表述

中文字符频率统计python_用Python数据分析方法进行汉字声调频率统计分析-程序员宅基地

文章浏览阅读259次。用Python数据分析方法进行汉字声调频率统计分析木合塔尔·沙地克;布合力齐姑丽·瓦斯力【期刊名称】《电脑知识与技术》【年(卷),期】2017(013)035【摘要】该文首先用Python程序,自动获取基本汉字字符集中的所有汉字,然后用汉字拼音转换工具pypinyin把所有汉字转换成拼音,最后根据所有汉字的拼音声调,统计并可视化拼音声调的占比.【总页数】2页(13-14)【关键词】数据分析;数据可..._汉字声调频率统计

linux输出信息调试信息重定向-程序员宅基地

文章浏览阅读64次。最近在做一个android系统移植的项目,所使用的开发板com1是调试串口,就是说会有uboot和kernel的调试信息打印在com1上(ttySAC0)。因为后期要使用ttySAC0作为上层应用通信串口,所以要把所有的调试信息都给去掉。参考网上的几篇文章,自己做了如下修改,终于把调试信息重定向到ttySAC1上了,在这做下记录。参考文章有:http://blog.csdn.net/longt..._嵌入式rootfs 输出重定向到/dev/console

随便推点

uniapp 引入iconfont图标库彩色symbol教程_uniapp symbol图标-程序员宅基地

文章浏览阅读1.2k次,点赞4次,收藏12次。1,先去iconfont登录,然后选择图标加入购物车 2,点击又上角车车添加进入项目我的项目中就会出现选择的图标 3,点击下载至本地,然后解压文件夹,然后切换到uniapp打开终端运行注:要保证自己电脑有安装node(没有安装node可以去官网下载Node.js 中文网)npm i -g iconfont-tools(mac用户失败的话在前面加个sudo,password就是自己的开机密码吧)4,终端切换到上面解压的文件夹里面,运行iconfont-tools 这些可以默认也可以自己命名(我是自己命名的_uniapp symbol图标

C、C++ 对于char*和char[]的理解_c++ char*-程序员宅基地

文章浏览阅读1.2w次,点赞25次,收藏192次。char*和char[]都是指针,指向第一个字符所在的地址,但char*是常量的指针,char[]是指针的常量_c++ char*

Sublime Text2 使用教程-程序员宅基地

文章浏览阅读930次。代码编辑器或者文本编辑器,对于程序员来说,就像剑与战士一样,谁都想拥有一把可以随心驾驭且锋利无比的宝剑,而每一位程序员,同样会去追求最适合自己的强大、灵活的编辑器,相信你和我一样,都不会例外。我用过的编辑器不少,真不少~ 但却没有哪款让我特别心仪的,直到我遇到了 Sublime Text 2 !如果说“神器”是我能给予一款软件最高的评价,那么我很乐意为它封上这么一个称号。它小巧绿色且速度非

对10个整数进行按照从小到大的顺序排序用选择法和冒泡排序_对十个数进行大小排序java-程序员宅基地

文章浏览阅读4.1k次。一、选择法这是每一个数出来跟后面所有的进行比较。2.冒泡排序法,是两个相邻的进行对比。_对十个数进行大小排序java

物联网开发笔记——使用网络调试助手连接阿里云物联网平台(基于MQTT协议)_网络调试助手连接阿里云连不上-程序员宅基地

文章浏览阅读2.9k次。物联网开发笔记——使用网络调试助手连接阿里云物联网平台(基于MQTT协议)其实作者本意是使用4G模块来实现与阿里云物联网平台的连接过程,但是由于自己用的4G模块自身的限制,使得阿里云连接总是无法建立,已经联系客服返厂检修了,于是我在此使用网络调试助手来演示如何与阿里云物联网平台建立连接。一.准备工作1.MQTT协议说明文档(3.1.1版本)2.网络调试助手(可使用域名与服务器建立连接)PS:与阿里云建立连解释,最好使用域名来完成连接过程,而不是使用IP号。这里我跟阿里云的售后工程师咨询过,表示对应_网络调试助手连接阿里云连不上

<<<零基础C++速成>>>_无c语言基础c++期末速成-程序员宅基地

文章浏览阅读544次,点赞5次,收藏6次。运算符与表达式任何高级程序设计语言中,表达式都是最基本的组成部分,可以说C++中的大部分语句都是由表达式构成的。_无c语言基础c++期末速成