在WPF的访问,如数据的导航? [英] access-like data navigation in WPF?
问题描述
什么是建立一个数据导航就像在XAML / C#在接入方式的最佳方法是什么?
What would be the best way to build a data-navigation like in access-forms in XAML/C#?
我应该建立一个用户控件(或者甚至是自定义控制),我只是绑定到我的收藏中,我可以把其他控件? (因此这个问题:的http://计算器.COM /问题/ 969835 / C-用户控制的可任意包含 - 其他 - 控制 - - 使用 - 它时,)
Should I build a user control (or even custom control) that I just bind to my collection in which I can put other controls? (hence this question: http://stackoverflow.com/questions/969835/c-user-control-that-can-contain-other-controls-when-using-it )
还是可以的我从那么莫名其妙ItemsControl的派生建立的东西?怎么样?
Or can I build something by deriving from then ItemsControl somehow? how?
或者这会不会今天做完全不同的(如这种风格的导航是如此,去年!)?
Or would this be done completely different today (like "this style of navigation is so last year!")?
我是比较新的C#和所有的(不是编程本身,而是更喜欢师奶语言接入VBA)还我不是以英语为母语。所以,请温柔=)
I'm relatively new to C# and all (not programming as such, but with more like "housewife-language" Access-VBA) also I'm no native english speaker. So pls be gentle =)
推荐答案
您可以创建用户控制和放置一堆按钮(首先,上一页,下一页,最后等)中并将其放置在主窗口中。其次,你可以将数据导航用户控件绑定到 CollectionViewSource
这将帮助你以你的数据之间的导航。
You can create user control and place a bunch of buttons (First, Prev, Next, Last, etc..) in it and place it on the main window. Secondly, you can bind your data navigation user control to a CollectionViewSource
which will help you to navigate among your data.
你的主窗口:
<Window.Resources>
<CollectionViewSource x:Key="items" Source="{Binding}" />
</Window.Resources>
<Grid>
<WpfApplication1:DataNavigation DataContext="{Binding Source={StaticResource items}}" />
<StackPanel>
<TextBox Text="{Binding Source={StaticResource items},Path=Name}" />
</StackPanel>
</Grid>
您数据导航用户控件:
<StackPanel>
<Button x:Name="Prev" Click="Prev_Click"><</Button>
<Button x:Name="Next" Click="Next_Click">></Button>
<!-- and so on -->
</StackPanel>
和你的点击处理程序是这样的:
And your click handlers goes like this:
private void Prev_Click(object sender, RoutedEventArgs e)
{
ICollectionView view = CollectionViewSource.GetDefaultView(DataContext);
if (view != null)
{
view.MoveCurrentToPrevious();
}
}
我希望这有助于。
I hope this helps.
这篇关于在WPF的访问,如数据的导航?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!