WPF中类似访问的数据导航?

access-like data navigation in WPF?(WPF中类似访问的数据导航?)
本文介绍了WPF中类似访问的数据导航?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 XAML/C# 中的访问表单中构建数据导航的最佳方式是什么?

What would be the best way to build a data-navigation like in access-forms in XAML/C#?

我是否应该构建一个用户控件(甚至是自定义控件),然后将其绑定到我的集合中,以便在其中放置其他控件?(因此这个问题:C# User Control that can包含其他控件(使用时))

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: 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# 和所有东西都比较陌生(不是这样编程,而是更像家庭主妇语言"Access-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 =)

推荐答案

您可以创建用户控件并在其中放置一堆按钮(First、Prev、Next、Last 等)并将其放置在主窗口上.其次,您可以将数据导航用户控件绑定到 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>

您的数据导航用户控件:

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();
    }
}

我希望这会有所帮助.

这篇关于WPF中类似访问的数据导航?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)