在 Wpf 中为 ListView 构建分页用户控件

发布于 2024-10-08 22:46:05 字数 1249 浏览 0 评论 0原文

我在 WPF 窗口中有一个 ListView 。此 ListView 绑定到强类型列表。
我有10个这样的Windows。每个都有一个绑定到强类型列表的 Listview。
我有一个 StackPanel,带有 4 个按钮和一个位于 ListView 下方的标签,用作 ListView 的寻呼机。目前,我正在窗口的代码隐藏中处理按钮事件。

谁能指导我将寻呼机的这一部分设为用户控件? 我感到困惑的部分是..如何处理后面代码中的 List

1) 如何访问 Window 代码隐藏中的用户控件属性。
2)我在哪里对列表进行实际过滤并将项目源设置为列表视图。

<StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
        <Button Name="btnFirst" Content="&lt;&lt;" Margin="2,2,15,2" Width="20"  Height="20" Tag="First"  ToolTip="First" Click="btnNav_Click"/>
        <Button Name="btnPrev" Content="&lt;" 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="&gt;" Margin="2,2,15,2" Width="20" Height="20" Tag="Next"  ToolTip="Next" Click="btnNav_Click"/>
        <Button Name="btnLast" Content="&gt;&gt;" Margin="2,2,0,2" Width="20" Height="20" Tag="Last"  ToolTip="Last" Click="btnNav_Click"/>
    </StackPanel>

I have a ListView in a WPF Window. This ListView is binded to a strongly typed list.
I have 10 Windows like this. each having a Listview binded to a strongly typed list.
I have a 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"  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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

谢谢大家!...但这不是我想要的!...
我有分页实现..但我想让它通用并制作一个可以在每个 wpf 窗口中重用的用户控件。

我是这样做的。

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

这是控件的用户界面,它看起来像

现在的类..
http://pastebin.com/jGywtEgG

在窗口的 Xaml 处。其中您显示带有绑定强类型列表的列表视图。
将用户控件放置在列表视图下方。

设置listview的itemsource = {Binding ElementName =“nameof the usercontrol”,Path = CurrentView}

CurrentView是在实现了Inotifypropertychanged的类中公开的属性。
差不多就这样了。

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.

风启觞 2024-10-15 22:46:05

这是 Beth MassiWindowsClient.net 上制作的精彩视频教程。它涵盖了分页以及许多有助于在 WPF 中创建以数据为中心的应用程序的概念。

如何:在 WPF 中创建简单的数据输入表单

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文