分页功能

1.xaml

 <Border Grid.Row="2">
                <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
                    <TextBlock  Text="首页"  Style="{StaticResource PageTextBlock}" 
                                cal:Message.Attach="[Event MouseLeftButtonUp]=[Action HomePage];[Event MouseEnter]=[Action PageGotFocus($view,$eventArgs)];[Event MouseLeave]=[Action PageLostFocus($view,$eventArgs)]"/>
                    <TextBlock  Text="上一页"  Style="{StaticResource PageTextBlock}" 
                                cal:Message.Attach="[Event MouseLeftButtonUp]=[Action PreviousPage];[Event MouseEnter]=[Action PageGotFocus($view,$eventArgs)];[Event MouseLeave]=[Action PageLostFocus($view,$eventArgs)]"/>
                    <TextBlock  Text="下一页" Style="{StaticResource PageTextBlock}" 
                                cal:Message.Attach="[Event MouseLeftButtonUp]=[Action NextPage];[Event MouseEnter]=[Action PageGotFocus($view,$eventArgs)];[Event MouseLeave]=[Action PageLostFocus($view,$eventArgs)]"/>
                    <TextBlock  Text="未页"  Style="{StaticResource PageTextBlock}" 
                                cal:Message.Attach="[Event MouseLeftButtonUp]=[Action EndPage];[Event MouseEnter]=[Action PageGotFocus($view,$eventArgs)];[Event MouseLeave]=[Action PageLostFocus($view,$eventArgs)]"/>
                    <TextBox Text="{Binding PageTrueNum}" Name="page" MaxLength="6" IsReadOnly="False" Style="{StaticResource PageTextBox}" />
                    <TextBlock   Text="GO"  Style="{StaticResource PageTextBlock}" 
                                 cal:Message.Attach="[Event MouseLeftButtonUp]=[Action GoPage(page.Text)];[Event MouseEnter]=[Action PageGotFocus($view,$eventArgs)];[Event MouseLeave]=[Action PageLostFocus($view,$eventArgs)]"/>
                    <TextBlock  Text="共"  Style="{StaticResource PageTextBlock}" />
                    <TextBlock  Text="{Binding PageAll}" Style="{StaticResource PageTextBlock}" />
                    <TextBlock  Text="页"  Style="{StaticResource PageTextBlock}" />
                    <TextBlock Text="每页" Style="{StaticResource PageTextBlock}" />
                    <TextBlock Text="20"  Foreground="{Binding PageIdex, Mode=TwoWay, Converter={StaticResource idexcolor20}}"  Style="{StaticResource PageTextBlock1}"
                               cal:Message.Attach="[Event MouseLeftButtonUp]=[Action SetPage($view)]"/>
                    <TextBlock Text="50"  Foreground="{Binding PageIdex, Mode=TwoWay, Converter={StaticResource idexcolor50}}"  Style="{StaticResource PageTextBlock1}"
                               cal:Message.Attach="[Event MouseLeftButtonUp]=[Action SetPage($view)]"/>
                    <TextBlock Text="100"  Foreground="{Binding PageIdex, Mode=TwoWay, Converter={StaticResource idexcolor100}}" Style="{StaticResource PageTextBlock1}"
                               cal:Message.Attach="[Event MouseLeftButtonUp]=[Action SetPage($view)]"/>
                    <TextBlock Text="200"  Foreground="{Binding PageIdex, Mode=TwoWay, Converter={StaticResource idexcolor200}}" Style="{StaticResource PageTextBlock1}"
                               cal:Message.Attach="[Event MouseLeftButtonUp]=[Action SetPage($view)]"/>
                    <TextBlock Text="个" Style="{StaticResource PageTextBlock}" />
                </StackPanel>
            </Border>
 <Style x:Key="PageTextBlock" TargetType="TextBlock">
            <Setter Property="VerticalAlignment" Value="Center" />
            <Setter Property="HorizontalAlignment" Value="Center" />
            <Setter Property="Margin" Value="0,0,10,0" />
            <Setter Property="FontSize" Value="13" />
            <Setter Property="Cursor" Value="Hand" />
            <Setter Property="Foreground" Value="#FF333333" />
        </Style>

        <Style x:Key="PageTextBlock1" TargetType="TextBlock">
            <Setter Property="VerticalAlignment" Value="Center" />
            <Setter Property="HorizontalAlignment" Value="Center" />
            <Setter Property="Margin" Value="0,0,10,0" />
            <Setter Property="FontSize" Value="13" />
            <Setter Property="Cursor" Value="Hand" />
        </Style>

        <Style x:Key="PageTextBox" TargetType="TextBox">
            <Setter Property="Height" Value="25" />
            <Setter Property="Width" Value="40" />
            <Setter Property="BorderBrush" Value="LightGray" />
            <Setter Property="HorizontalAlignment" Value="Center" />
            <Setter Property="VerticalAlignment" Value="Bottom" />
        </Style>

2.cs

  public void NextPage()
        {
            PageNum++;
            if (PageNum == PageAll)
            {
                PageNum = PageAll - 1;
            }
            PageList.Clear();
            for (int i = PageNum * PageIdex; i < DugList.Count; i++)
            {
                if (i < PageNum * PageIdex + PageIdex)
                {
                    PageList.Add(DugList[i]);
                }
            }
        }
        public void PreviousPage()
        {
            PageNum--;
            if (PageNum == -1)
            {
                PageNum = 0;
            }
            PageList.Clear();
            for (int i = PageNum * PageIdex; i < DugList.Count; i++)
            {
                if (i < PageNum * PageIdex + PageIdex)
                {
                    PageList.Add(DugList[i]);
                }
            }
        }
        public void HomePage()
        {
            PageNum = 0;
            PageList.Clear();
            for (int i = PageNum * PageIdex; i < DugList.Count; i++)
            {
                if (i < PageNum * PageIdex + PageIdex)
                {
                    PageList.Add(DugList[i]);
                }
            }
        }
        public void EndPage()
        {
            PageNum = PageAll-1;
            PageList.Clear();
            for (int i = PageNum * PageIdex; i < DugList.Count; i++)
            {
                if (i < PageNum * PageIdex + PageIdex)
                {
                    PageList.Add(DugList[i]);
                }
            }
        }
        public void GoPage(string view)
        {
            PageTrueNum=int.Parse(view.Trim());
            PageNum = PageTrueNum - 1;
            if (PageNum == PageAll)
            {
                PageNum = PageAll - 1;
            }
            if (PageNum < 0)
            {
                PageNum = 0;
            }
            PageList.Clear();
            for (int i = PageNum * PageIdex; i < DugList.Count; i++)
            {
                if (i < PageNum * PageIdex + PageIdex)
                {
                    PageList.Add(DugList[i]);
                }
            }
        }
        public void SetPage(object sender)
        {
            TextBlock tb = (sender as TextBlock);

            PageIdex = int.Parse(tb.Text.ToString());
        }
        public void PageGotFocus(object sender, RoutedEventArgs e)
        {
            TextBlock text = (TextBlock)sender;
            text.TextDecorations = TextDecorations.Underline;
            text.Foreground = new SolidColorBrush(Colors.Blue);
        }
        public void PageLostFocus(object sender, RoutedEventArgs e)
        {
            TextBlock text = (TextBlock)sender;
            text.TextDecorations = null;
            text.Foreground = new SolidColorBrush(Colors.Black);
        }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值