如何从列表框中选择的项目中获取特定属性 [英] How to get particular property from item selected in ListBox

查看:72
本文介绍了如何从列表框中选择的项目中获取特定属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下内容:

<ListBox SelectedItem="{Binding SelectedItem}"
ItemsSource="{Binding items}" DisplayMemberPath="s"/>

<TextBlock Text="{Binding SelectedItem.s}"/>

这是SelectedItem

public MemEntity SelectedItem {get; set;}

MemEntity是一个包含

public String s {get; get;}.

基本上,我希望所选项目的s显示在TextBlock中(与ListBox中显示的属性相同).这行不通,所以我在做什么错了?

Basically, I want s of the selected item to be shown in the TextBlock (same property as shown in ListBox). This doesn't work, so what am I doing wrong?

推荐答案

尝试一下,

<TextBlock ... Text="{Binding ElementName=items, Path=SelectedItem.s}" />

然后将名称添加为您的列表框,

then add a name to your ListBox as,

  <ListBox x:Name="items" SelectedItem="{Binding SelectedItem}"
        ItemsSource="{Binding items}" DisplayMemberPath="s"/>

这篇关于如何从列表框中选择的项目中获取特定属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆