WPF中的访问类数据导航? [英] access-like data navigation in WPF?
问题描述
如果您建立一个用户控件(甚至是自定义的),那么建立数据导航的最佳方法就是像在XAML / C#控制),我刚刚绑定到我的集合,其中我可以把其他控件? (因此这个问题:可以使用C#用户控制包含其他控件(使用它时))
或者可以通过派生出ItemsControl来构建东西吗?如何?
或者今天做的完全不一样(像去年这样的导航风格)?
我比较新的C#和所有(不是这样编程,但更像家庭主妇语言Access-VBA)我也不是英文的本地人。您可以创建用户控件并放置一堆按钮(第一,上一页,下一页,最后一页)
,等等),并将其放在主窗口上。其次,您可以将数据导航用户控件绑定到一个 CollectionViewSource
,这将有助于您在数据之间导航。
您的主窗口:
< Window.Resources>
< CollectionViewSource x:Key =itemsSource ={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 =PrevClick =Prev_Click>& lt;< / Button>
< Button x:Name =NextClick =Next_Click>& gt< / Button>
<! - 等等 - >
< / StackPanel>
您的点击处理程序如下所示:
private void Prev_Click(object sender,RoutedEventArgs e)
{
ICollectionView view = CollectionViewSource.GetDefaultView(DataContext);
if(view!= null)
{
view.MoveCurrentToPrevious();
}
}
希望这有帮助。
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: 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 =)
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"><</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屋!