如何从 WPF/XAML ListView 读取子项值?
够了 - 我刚刚花了一个小时四处搜索,试图找出如何从 ListView 读取 ListViewSubItem 值(如果这是 XAML 中的正确术语)。这是一个小ListView:
<ListView x:Name="CreatableAccounts" ItemsSource="{Binding Processable}" Margin="10,0">
<ListView.View>
<GridView>
<GridViewColumn Header="Site Name" DisplayMemberBinding="{Binding SiteName}"/>
<GridViewColumn Header="From Package" DisplayMemberBinding="{Binding FiCodeDLL.Name}"/>
</GridView>
</ListView.View>
</ListView>
这是我尝试读取显然行不通的值:
private void CreateAccounts_Click(object sender, RoutedEventArgs e)
{
ListViewItem selected = CreatableAccounts.SelectedItem;
selected.Ite // no Items, Text or similar property
}
任何人都可以指出我正确的方向吗?提前感谢您的帮助!
Enough is enough - I've just spent an hour searching around trying to find out how to read the ListViewSubItem values (if that's correct terminology in XAML) from a ListView. Here's a little ListView:
<ListView x:Name="CreatableAccounts" ItemsSource="{Binding Processable}" Margin="10,0">
<ListView.View>
<GridView>
<GridViewColumn Header="Site Name" DisplayMemberBinding="{Binding SiteName}"/>
<GridViewColumn Header="From Package" DisplayMemberBinding="{Binding FiCodeDLL.Name}"/>
</GridView>
</ListView.View>
</ListView>
and here's my attempt to read the values which is clearly not going to work:
private void CreateAccounts_Click(object sender, RoutedEventArgs e)
{
ListViewItem selected = CreatableAccounts.SelectedItem;
selected.Ite // no Items, Text or similar property
}
Can anyone point me in the right direction? Grazie in advance for your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
ListView 有一个依赖属性“SelectedItem”,您可以将集合子项的实例绑定到该属性,因此:
现在您可以创建一个 ViewModel,它公开填充了您的项目的 ObservableCollection,以及作为您的 SelectedItem 的项目的单个实例...
类似:
希望这有帮助:)
Ian
The ListView has a dependency property "SelectedItem" to which you can bind an instance of your collection child item, thus:
Now you can create a ViewModel that exposes an ObservableCollection filled with your items, and a single instance of an item which is your SelectedItem...
something like:
Hope this helps :)
Ian