access-like data navigation in WPF?

扶醉桌前 提交于 2019-12-04 19:54:18

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.

Your main window:

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

Your Data Navigation User Control:

<StackPanel>
    <Button x:Name="Prev" Click="Prev_Click">&lt;</Button>
    <Button x:Name="Next" Click="Next_Click">&gt;</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.

Sounds like you're after a DataGrid control. Microsoft is releasing a WPF DataGrid as part of a WPF Toolkit which you can download here: http://wpf.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=25047.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!