Building a Paging UserControl for ListView in Wpf
I have a ListView
in a WPF Window. This ListView
is binded to a strongly typed list.
StackPanel
with 4 buttons and a Label Below the ListView
that serves as a Pager for the ListView
. Currently, I am handling the Buttons events in the Code behind for the window.
Can anyone guide me on making this part of the pager a UserControl?
The part i am confused in is.. How do I handle the List<type>
in the Code behind?
1) How do i Access the Usercontrol properties in the Codebehind for Window.
2) Where do i do the Actual Filtering for the list and Set the itemsource to the listview.<StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
<Button Name="btnFirst" Content="<<" Margin="2,2,15,2" Width="20" Height="20" Tag="First" ToolTip="First" Click="btnNav_Click"/>
<Button Name="btnPrev" Content="<" Margin="2,2,15,2" Width="20" Height="20" Tag="Prev" ToolTip="Previous" Click="btnNav_Click"/>
<Label Name="lblPage" Margin="2,2,15,2" HorizontalAlignment="Center" VerticalAlignment="Center"/>
<Button Name="btnNext" Content=">" Margin="2,2,15,2" Width="20" Height="20" Tag="Next" Too开发者_JAVA百科lTip="Next" Click="btnNav_Click"/>
<Button Name="btnLast" Content=">>" Margin="2,2,0,2" Width="20" Height="20" Tag="Last" ToolTip="Last" Click="btnNav_Click"/>
</StackPanel>
Thnkx Guys!.. But that is not what i was looking for !.. I have the paging imlementation with me .. but i want to make it generic and make a usercontrol that i could reuse in every wpf window.
Here's how i did it.
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
<Button Name="btnFirst" Content="<<" Margin="2,2,10,2" Width="20" Height="20" Tag="First" ToolTip="First" Click="btnNav_Click"/>
<Button Name="btnPrev" Content="<" Margin="2,2,10,2" Width="20" Height="20" Tag="Prev" ToolTip="Previous" Click="btnNav_Click"/>
<Label HorizontalAlignment="Center" VerticalAlignment="Center" Content="Page :" Margin="2,2,0,2"/>
<ComboBox Name="cmbxPageNo" HorizontalAlignment="Left" Margin="1,2,4,0" HorizontalContentAlignment="Center" VerticalContentAlignment="Bottom" VerticalAlignment="Center" Width="35" Style="{StaticResource PagerCmbx}" SelectionChanged="cmbxPageNo_SelectionChanged" Height="18" ItemsSource="{Binding}"/>
<Label Name="lblTotPage" HorizontalAlignment="Left" VerticalAlignment="Center" FontSize="14" Content="/ 5"/>
<Button Name="btnNext" Content=">" Margin="15,2,10,2" Width="20" Height="20" Tag="Next" ToolTip="Next" Click="btnNav_Click"/>
<Button Name="btnLast" Content=">>" Margin="2,2,0,2" Width="20" Height="20" Tag="Last" ToolTip="Last" Click="btnNav_Click"/>
</StackPanel>
This is the ui for the control which would look like
now for the class..
http://pastebin.com/jGywtEgG
At the Xaml for the window . where u show the listview with the binded strongly typed list. Place the Usercontrol below the listview.
Set the itemsource for the listview={Binding ElementName = "nameof the usercontrol",Path = CurrentView}
CurrentView is the Property exposed in the class with Inotifypropertychanged implemented. That's pretty much it.
Here is a good video tutorial by Beth Massi on WindowsClient.net
. It covers paging along with many concepts useful for creating a Data-Centric application in WPF
.
How Do I: Create a Simple Data Entry Form in WPF
精彩评论