I am use xamwebgrid 10.1 in silverlight project, besides the default pager, I also like to show some text like " 1 - 25 of 91 records" on the left side of the pager area, my implement is :
XAML: where Items is a VirtualCollection<myType> object
<igGrid:XamWebGrid x:Name="subscriptions" Grid.Row="3" AutoGenerateColumns="False" RowHover="Row" ItemsSource="{Binding Items}" > <igGrid:XamWebGrid.PagerSettings> <igGrid:PagerSettings PageSize="25" Style="{StaticResource customPager}" AllowPaging="Bottom" > </igGrid:PagerSettings> </igGrid:XamWebGrid.PagerSettings> <igGrid:XamWebGrid.Columns>
........
</igGrid:XamWebGrid>
in APP.xaml I defined style of customPager as :
<Style x:Name="customPager" TargetType="igPrim:PagerCellControl" > <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="igPrim:PagerCellControl"> <Grid Background="#EEE"> <Grid.ColumnDefinitions> <ColumnDefinition Width="auto" /> <ColumnDefinition Width="*" /> </Grid.ColumnDefinitions> <StackPanel HorizontalAlignment="Left" Orientation="Horizontal" Margin="5,5,0,0"> <TextBlock Text="{Binding Mode=TwoWay, Converter={StaticResource virtualCollectionToPageSummaryConverter}, Path=Parent.Owner.Grid.ItemsSource.PageIndex, RelativeSource={RelativeSource TemplatedParent}}" /> <TextBlock Text=" - " /> <TextBlock Text="{Binding Mode=TwoWay, Converter={StaticResource virtualCollectionToPageSummaryConverter}, ConverterParameter=1, Path=Parent.Owner.Grid.ItemsSource.PageIndex, RelativeSource={RelativeSource TemplatedParent}}" /> <TextBlock Text=" of " /> <TextBlock Text="{Binding Mode=TwoWay, Path=Parent.Owner.Grid.ItemsSource.TotalItemCount, RelativeSource={RelativeSource TemplatedParent} }" /> <TextBlock Text=" records" /> </StackPanel> <igPrim:PagerControl x:Name="PagerItemControl" Grid.Column="1"> <!-- Execute command on PagerCellControl when a specific PagerControl event occurs--> <Controls1:Commanding.Commands> <igGrid:XamWebGridPagingCommandSource EventName="FirstPage" CommandType="FirstPage" > </igGrid:XamWebGridPagingCommandSource> <igGrid:XamWebGridPagingCommandSource EventName="LastPage" CommandType="LastPage" > </igGrid:XamWebGridPagingCommandSource> <igGrid:XamWebGridPagingCommandSource EventName="PreviousPage" CommandType="PreviousPage" > </igGrid:XamWebGridPagingCommandSource> <igGrid:XamWebGridPagingCommandSource EventName="NextPage" CommandType="NextPage" > </igGrid:XamWebGridPagingCommandSource> <igGrid:XamWebGridPagingCommandSource EventName="GoToPage" CommandType="GoToPage" > </igGrid:XamWebGridPagingCommandSource> </Controls1:Commanding.Commands> </igPrim:PagerControl> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style>
And the converter default as:
public class VirtualCollectionToPageSummaryConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { int result = 0; var pageIndex = (int)value; if( parameter == null) { result = pageIndex*25 + 1; } else { result = (pageIndex + 1)*25; } return result; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); } }
Issue:
Basic all work perfect except the one: when you click those pager item to the last page, the text will be show as " 76 - 100 of 91 records " which should be " 76 - 91 of 91 records" for the last page.
So how to fix this issue? Thanks!
Please find attached.
This is the 'quick and dirty' solution suggested here: http://www.codeproject.com/Articles/285104/Silverlight-Multi-Binding
From the code you provided I assume you're using version 10.1 (or older), so I used this version for the sample app as well.
Hope this helps,
Any solution, Expert?
Thank you Georgi.
However, I added the MultiBinding in my project, and get no luck. Actually in the demo project, the MultiBinding support three type for the BindingCollection:
1. <Binding Path="Surname" />
2. <Binding Path="Surname" Mode="TwoWay"/>
3. <Binding ElementName="sliderOne" Path="Value"/>
However, in my scenario, How to get it? I tried below and not success:
<Binding Path="Parent.Owner.Grid.ItemsSource.PageIndex" />
or
<TextBlock x:Name="txtPageIndex" Text="{Binding Mode=TwoWay, Converter={StaticResource virtualCollectionToPageSummaryConverter}, Path=Parent.Owner.Grid.ItemsSource.PageIndex, RelativeSource={RelativeSource TemplatedParent}}" />
<Binding ElementName="txtPageIndex" Path="Text"/>
Thanks in Advance.
Hi,
It would be nice if Silverlight supported MultiBinding - that would be the most elegant way to handle this scenario. However, there are a number of custom implementations of MultiBinding for Silverlight that you could adopt and use in this case.
Doing that will allow you to pass both the PageIndex and TotalItemCount to your converter, and have something like this in the 'else' statement of your converter logic:
else { result = (pageIndex + 1)*25; if (result > totaltemCount) { result = totaItemCount; } }
You could check-out this article that demonstrates a MultiBinding solution for Silverlight 4:
http://www.scottlogic.co.uk/blog/colin/2010/05/silverlight-multibinding-solution-for-silverlight-4/