3

いくつかの ComboBoxes を 1 つの ObservableCollection にバインドする必要があります。私はこれを持っていますListView

<ListView x:Name="lwCoefTables" Grid.Column="1" ItemsSource="{Binding Source={StaticResource CollectionCoefContainers}}">
<ListView.ItemTemplate>
    <DataTemplate>
        <ComboBox x:Name="cmbCoefTableTypes" ItemsSource="{Binding Source={StaticResource CollectionCoefLinksTable}}"  
                SelectedItem="{Binding CoefLinksTableType, Mode=TwoWay}" Grid.Column="1" VerticalAlignment="Center" 
                HorizontalAlignment="Left" Width="180" DisplayMemberPath="Name">
        </ComboBox>
    </DataTemplate>
</ListView.ItemTemplate>

コレクションをすべての ComboBoxes にバインドし、ComboBox ごとに選択したアイテムを保存します。TwoWay モードで 1 つのコレクションを埋めてすべてのコンボボックスにバインドすると、次のようになります。

写真

同様のコレクションを含むヘルパー クラスが必要だと思います。どうやってするか?

4

1 に答える 1

3

だから私はCoefLinksTableTypeプロパティがアイテムの中にあるとCollectionCoefContainers思いますか?

その場合、同じインスタンスが 内で繰り返されていない限りCollectionCoefContainers、これは機能するはずです。

例えば

このようなものは、あなたが説明したように動作します。

var vm = new VM();
CollectionCoefContainers.Add(vm);
CollectionCoefContainers.Add(vm);
CollectionCoefContainers.Add(vm);
CollectionCoefContainers.Add(vm);

解決策は

CollectionCoefContainers.Add(new VM());
CollectionCoefContainers.Add(new VM());
CollectionCoefContainers.Add(new VM());
CollectionCoefContainers.Add(new VM());

CollectionCoefContainersと の定義があると便利です。CollectionCoefLinksTable

于 2011-10-06T14:11:52.237 に答える