wpf 将文本绑定到父列表框的内容

发布于 2024-11-26 13:19:06 字数 450 浏览 4 评论 0原文

我有一个列表框,其项目将以文本框格式显示,如下所示:-

   <ListBox ItemsSource="{Binding movieList}" Name="innerList">
      <ListBox.ItemTemplate >
         <DataTemplate >
            <TextBox Text="-------" TextChanged="TextBox_TextChanged_1"/>
         </DataTemplate>
       </ListBox.ItemTemplate>
   </ListBox> 

编辑:

抱歉,电影列表是(电影的)可观察集合,而不是(字符串)

如何让文本框显示的内容它的祖先(innerList)?

I have a listBox whose items are to be shown in a textbox format, like so:-

   <ListBox ItemsSource="{Binding movieList}" Name="innerList">
      <ListBox.ItemTemplate >
         <DataTemplate >
            <TextBox Text="-------" TextChanged="TextBox_TextChanged_1"/>
         </DataTemplate>
       </ListBox.ItemTemplate>
   </ListBox> 

EDIT:

Sorry, movie list was an observablecollection (of Movie) instead of being (of String)

How do I get the textbox to show the contents of its ancestor (the innerList) ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

动次打次papapa 2024-12-03 13:19:06

如果您想在文本框中显示电影的标题,只需使用:(

<TextBox Text="{Binding Title}" TextChanged="TextBox_TextChanged_1"/>

假设列表中的项目是具有 Title 属性的对象)

If you want to display the title of a movie in the TextBox, just use that:

<TextBox Text="{Binding Title}" TextChanged="TextBox_TextChanged_1"/>

(assuming the items in the list are objects with a Title property)

顾北清歌寒 2024-12-03 13:19:06

来自绑定声明概述

可以选择使用句点 (.) 路径来绑定到当前
来源。例如,Text="{Binding}" 相当于 Text="{Binding
路径=.}”。

所以下面应该可以做到。

<TextBox Text="{Binding}" TextChanged="TextBox_TextChanged_1"/>

From Binding Declarations Overview

Optionally, a period (.) path can be used to bind to the current
source. For example, Text="{Binding}" is equivalent to Text="{Binding
Path=.}".

So following should do it.

<TextBox Text="{Binding}" TextChanged="TextBox_TextChanged_1"/>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文