views:

398

answers:

2

What would be the best way to build a data-navigation like in access-forms in XAML/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 )

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!")?

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

A: 

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.

AndrewS
Thanks for your answer, but a datagrid isnt what I need, I think. I have many different controls to put on my forms.
MAD9
Ah, I was thinking of excel rather than access. My bad :)
AndrewS
+1  A: 

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.

idursun
It works! I can navigate through the collection (checked the current item), but my other controls don't get updated with the current item of the collection. This could only be a small thing I believe ...
MAD9
Ok, got it. Its important, that the the controls that display the data are bound to the same resource as the navigation controls ...
MAD9