简体   繁体   English

Silverlight 4/5 DataPager模板PageSize ComboBox

[英]Silverlight 4/5 DataPager Template PageSize ComboBox

I have a Template defined for Silverlight DataPager control with a CombboBox with PageSize values 我有一个为Silverlight DataPager控件定义的模板,其中的CombboBox具有PageSize值

Template: 模板:

<Style TargetType="sdk:DataPager">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="sdk:DataPager">
                <Grid x:Name="Root" Background="Transparent">
                    <Border BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="2" MinHeight="24" Padding="{TemplateBinding Padding}"             VerticalAlignment="Bottom">
                        <StackPanel HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Orientation="Horizontal" VerticalAlignment="Stretch">
                            <Button x:Name="FirstPageButton" BorderBrush="{StaticResource BorderBrushColor}" BorderThickness="1" Background="{StaticResource BackgroundColor}" Foreground="{StaticResource ForegroundColor}" HorizontalAlignment="Right" Height="20" Padding="1" Template="{StaticResource ButtonTemplate}" VerticalAlignment="Center" Width="20" Margin="0,0,3,0">
                                <Grid Height="9" Width="8">
                                    <Path Data="M0,1 L1,0 L1,2 Z" HorizontalAlignment="Right" Height="9" Stretch="Fill" Width="5" Fill="White"/>
                                    <Rectangle HorizontalAlignment="Left" Width="2" Fill="White"/>
                                </Grid>
                            </Button>
                            <Button x:Name="PreviousPageButton" BorderBrush="{StaticResource BorderBrushColor}" BorderThickness="1" Background="{StaticResource BackgroundColor}" Foreground="{StaticResource ForegroundColor}" HorizontalAlignment="Right" Height="20" Padding="1" Template="{StaticResource ButtonTemplate}" VerticalAlignment="Center" Width="20" Margin="0,0,3,0">
                                <Path Data="M0,1 L1,0 L1,2 Z" HorizontalAlignment="Center" Height="9" Stretch="Fill" Width="5" Fill="White"/>
                            </Button>
                            <Border x:Name="Separator1" BorderThickness="1,0,1,0" Margin="0, 3" Width="1" BorderBrush="#FF747474"/>
                            <StackPanel x:Name="NumericButtonPanel" Margin="1" Orientation="Horizontal"/>
                            <StackPanel x:Name="PageSizeDisplay" Orientation="Horizontal">


                                <ComboBox SelectedValue="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=PageSize, Mode=TwoWay}" 
                                          SelectedValuePath="Content" Width="60" Margin="3"
                                          BorderBrush="{TemplateBinding BorderBrush}" Foreground="{TemplateBinding Foreground}">
                                    <ComboBoxItem Content="10"></ComboBoxItem>
                                    <ComboBoxItem Content="20" IsSelected="True"></ComboBoxItem>
                                    <ComboBoxItem Content="50"></ComboBoxItem>
                                    <ComboBoxItem Content="100"></ComboBoxItem>
                                    <ComboBoxItem Content="200"></ComboBoxItem>
                                </ComboBox>


                            </StackPanel>
                            <StackPanel x:Name="PageDisplay" Orientation="Horizontal">
                                <TextBlock x:Name="CurrentPagePrefixTextBlock" Foreground="{TemplateBinding Foreground}" Margin="4,0,0,0" VerticalAlignment="Center" Width="Auto"/>
                                <TextBox x:Name="CurrentPageTextBox" BorderBrush="{TemplateBinding BorderBrush}" Foreground="{TemplateBinding Foreground}" Height="Auto" Margin="4,2,4,2" Style="{StaticResource TextBoxStyle1}" TextWrapping="Wrap" VerticalAlignment="Center" Width="40"/>
                                <TextBlock x:Name="CurrentPageSuffixTextBlock" Foreground="{TemplateBinding Foreground}" Margin="0,0,4,0" VerticalAlignment="Center" Width="Auto"/>
                            </StackPanel>
                            <Border x:Name="Separator2" BorderThickness="1,0,1,0" Margin="0,3" Width="1" BorderBrush="#FF747474"/>
                            <Button x:Name="NextPageButton" BorderBrush="{StaticResource BorderBrushColor}" BorderThickness="1" Background="{StaticResource BackgroundColor}" Foreground="{StaticResource ForegroundColor}" HorizontalAlignment="Right" Height="20" Padding="1" Template="{StaticResource ButtonTemplate}" VerticalAlignment="Center" Width="20" Margin="3,0">
                                <Path Data="M0,0 L1,1 L0,2 Z" HorizontalAlignment="Center" Height="9" Stretch="Fill" Width="5" Fill="White"/>
                            </Button>
                            <Button x:Name="LastPageButton" BorderBrush="{StaticResource BorderBrushColor}" BorderThickness="1" Background="{StaticResource BackgroundColor}" Foreground="{StaticResource ForegroundColor}" HorizontalAlignment="Right" Height="20" Padding="1" Template="{StaticResource ButtonTemplate}" VerticalAlignment="Center" Width="20">
                                <Grid Height="9" Width="8">
                                    <Path Data="M0,0 L1,1 L0,2 Z" HorizontalAlignment="Left" Height="9" Stretch="Fill" Width="5" Fill="White"/>
                                    <Rectangle HorizontalAlignment="Right" Width="2" Fill="White"/>
                                </Grid>
                            </Button>
                        </StackPanel>
                    </Border>
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

Usage: 用法:

<sdk:DataPager x:Name="pager" Source="{Binding Path=ItemsSource, ElementName=myGrid}" PageSize="50" />

My DataGrid is bound to a PagedCollectionView , but still the PageSize ComboBox doesn't display the correct value. 我的DataGrid绑定到一个PagedCollectionView ,但仍PageSize ComboBox不显示正确的值。 (if IsSelected property is not set, there is no selected item in the ComboBox ) (如果未设置IsSelected属性,则ComboBox没有选定的项目)

I have also tried setting the PageSize property of the PagedCollectionView , that doesn't help either. 我也曾尝试设置PageSize的财产PagedCollectionView ,这并没有帮助。

Any idea what am I doing wrong? 知道我在做什么错吗?

You are trying to bind ComboBoxItem values with int32 values. 您试图将ComboBoxItem值与int32值绑定。

try this instead: 试试这个代替:

<ComboBox SelectedValue="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=PageSize, Mode=TwoWay}" 
Width="60" Margin="3"
BorderBrush="{TemplateBinding BorderBrush}" Foreground="{TemplateBinding Foreground}">

<sys:Int32>10</sys:Int32>
<sys:Int32>20</sys:Int32>
<sys:Int32>50</sys:Int32>

Also add the following namespace: 还添加以下名称空间:

xmlns:sys="clr-namespace:System;assembly=mscorlib"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM