1

テキストボックスを含むリストボックスを作成する必要があります...そして動的でなければなりません。コードビハインドに監視可能なコレクションがあり、それをリストボックスにバインドしたいと考えています。動的リストボックスが必要で、このリストには編集可能なテキストボックスが必要です。だから、基本的にリストボックスからマルチプルテキストボックスをバインドしたい。どんな助けでもいただければ幸いです

<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 Name="TextBoxList"></TextBox>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

これにより、オブザーバブル コレクション内のアイテムと同じ数のテキスト ボックスが作成されますが、テキスト ボックスのテキストは設定されません。

4

2 に答える 2

8

あなたの項目ObservableCollectionが単純なstrings である場合、次のように文字列値全体にデータバインドできます。

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

MSDNのBinding.Pathプロパティページから:

オプションで、ピリオド (.) パスを使用して現在のソースにバインドできます。たとえば、Text="{Binding}"は と同等Text="{Binding Path=.}"です。

コレクションにプロパティを持つオブジェクトがいくつかある場合、関連するプロパティ名を参照する必要があるため、@nit の答えは正しいことに注意してください。

<ListBox Name="ListTwo" ItemsSource="{Binding Source=obs}" ... >
    <ListBox.ItemTemplate>
        <DataTemplate>
            <TextBox Name="TextBoxList" Text="{Binding PropertyName}" />
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>
于 2014-06-03T15:05:54.117 に答える
1

テキストボックスを、バインドした監視可能なコレクションのクラスのプロパティにバインドする必要があります

<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>
于 2014-06-03T14:38:29.127 に答える