如何使列表视图与数据绑定一起使用?

编程入门 行业动态 更新时间:2024-10-25 16:21:33
本文介绍了如何使列表视图与数据绑定一起使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

伙计们 我已经设法在Xaml中进行数据绑定但不完全。 我有文本块和数据绑定工作。我在Windows应用程序中将信息从第2页传递到第3页。 我的列表视图完全相同,但根本不起作用。我不明白为什么。有人可以看看吗?

Hi, guys I've managed to do Data Binding in Xaml but not completely. I have got text block and Data Binding works. I'm passing information from page 2 to page3 in my windows app. I have done exactly the same with my List View and it doesn't work at all. I don't understand why. Can someone please have a look?

<ListView Name="detailsListView" Grid.Row="1" Height="300" Width="400" ItemsSource="{Binding Name}"/> <TextBlock Text="{Binding Name}" x:Name="myTextBlock" Grid.Row="1" Grid.Column="2" Height="200" Width="300" FontSize="28"/>

在我的代码背后数据上下文设置为页面布局

In my Code Behind The data context is set to the page layout

protected override void OnNavigatedTo(NavigationEventArgs e) { Nutrient nutriQuery = e.Parameter as Nutrient; if (nutriQuery != null) { DetailsPageLayout.DataContext = nutriQuery; }

为什么文本块可以工作而不是列表视图?

Why Text Block works but not List View?

推荐答案

您需要将ItemsSource绑定到ObservableCollection。您还需要定义ListView视图。这样的事情。

You need to bind the ItemsSource to an ObservableCollection. You also need to define the ListView View. Something like this. <!--In the view model, PersonCollection is a collection of type Person SelectedPerson is a property of type Person.Name and Age are properties defined inside the Person class--> <listview itemssource="{Binding PersonCollection}" selecteditem="{Binding SelectedPerson, Mode=TwoWay}" issynchronizedwithcurrentitem="True"> HorizontalAlignment="Center" Height="168" VerticalAlignment="Top" Width="400" Background="#FFBFBFBF"> <listview.view> <gridview> <gridviewcolumn width="280" header="Name" displaymemberbinding="{Binding Path=Name}" /> <gridviewcolumn width="60" header="Age" displaymemberbinding="{Binding Path=Age}" /> </gridview> </listview.view> </listview>

更多推荐

如何使列表视图与数据绑定一起使用?

本文发布于:2023-11-27 06:33:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1636978.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:视图   绑定   数据   列表

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!