0
私はWP7のためのXAMLを持っている:どのようにバインドさリストボックス内の項目にアクセスするには、WP7
<ListBox x:Name="lbMain" DataContext="{Binding}" ItemsSource="{Binding Items}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock x:Name="txtName" Text="{Binding name}" />
<ListBox x:Name="lbCars" DataContext="{Binding}" ItemsSource="{Binding cars}" ScrollViewer.VerticalScrollBarVisibility="Disabled">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel x:Name="spnlCars">
<TextBlock x:Name="txtCarName" Text="{Binding name}" />
<ListBox x:Name="lbCarColor" DataContext="{Binding}" ItemsSource="{Binding color}">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock x:Name="txtColor" Text="{Binding colorValue}"/>
<Image Name="imgColor"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
マイDataContexは、Webサービスからデータを取得している、私が作成したのViewModelに設定されています。データ構造は次のとおりです。
- マシン(あり:車は、[])
- -Vehicles(あり:名前、車[]、トラックは[]、...)----私は何を結合していますthatsの----例えば、色[0] = "赤"
- --- colorValue
I:lbMain
私は知りませんホットへ:
- txtColorに応じてリソースとは異なる画像を取得するために、各imgColorを設定し、 がtxtCarNameに太字フォントを適用すると、「txtColor.Text =(たとえば)赤"。
私はアドバイスと提案を感謝します。
素晴らしいdecycloneだ、ありがとう!それが私の最初の質問を探していた答えです。 私の2番目の質問に対する助けがありますか?親DataContexにアクセスしようとしたときに問題が発生し、古いListBoxItemを変更しようとしました。 – Slavisa
同じ方法でコンバーターを使用する必要があります。つまり、FontWeightをカラーにバインドし、コンバーターでColorをFontWeightにバインドします。 –
私はFrancescoに同意します。上記の例では 'BitmapImage'型の代わりに' FontWeight'型に色名を変換するために別のコンバータが必要です。 – decyclone