在 Wpf 中为 ListView 构建分页用户控件
我在 WPF 窗口中有一个 ListView
。此 ListView
绑定到强类型列表。
我有10个这样的Windows。每个都有一个绑定到强类型列表的 Listview。
我有一个 StackPanel
,带有 4 个按钮和一个位于 ListView
下方的标签,用作 ListView
的寻呼机。目前,我正在窗口的代码隐藏中处理按钮事件。
谁能指导我将寻呼机的这一部分设为用户控件? 我感到困惑的部分是..如何处理后面代码中的 List
?
1) 如何访问 Window 代码隐藏中的用户控件属性。
2)我在哪里对列表进行实际过滤并将项目源设置为列表视图。
<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>
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
谢谢大家!...但这不是我想要的!...
我有分页实现..但我想让它通用并制作一个可以在每个 wpf 窗口中重用的用户控件。
我是这样做的。
这是控件的用户界面,它看起来像
现在的类..
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.
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.
这是 Beth Massi 在
WindowsClient.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 inWPF
.How Do I: Create a Simple Data Entry Form in WPF