Bind textbox list inside listbox in wpf

倖福魔咒の 提交于 2019-12-02 07:26:20

You will have to Bind your textbox to the property in your class of which observable collection you have bound

<ListBox HorizontalAlignment="Left" Name="ListTwo" Height="100" Margin="286.769,165.499,0,0" VerticalAlignment="Top" Width="100" ItemsSource="{Binding Source=obs}">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <TextBox Binding="{Binding PROPERTYINCLASS}"></TextBox>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

If the items in your ObservableCollection are just plain strings, then you can data bind to the whole string value like this:

<ListBox Name="ListTwo" ItemsSource="{Binding Source=obs}" ... >
    <ListBox.ItemTemplate>
        <DataTemplate>
            <TextBox Name="TextBoxList" Text="{Binding}" />
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

From the Binding.Path Property page on MSDN:

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

Note that if you had some objects with properties in the collection, then @nit's answer would have been correct as you would need to reference the relevant property name:

<ListBox Name="ListTwo" ItemsSource="{Binding Source=obs}" ... >
    <ListBox.ItemTemplate>
        <DataTemplate>
            <TextBox Name="TextBoxList" Text="{Binding PropertyName}" />
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!