【发布时间】:2010-11-24 21:25:06
【问题描述】:
我有 WP7 的 XAML:
<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 设置为我创建的 ViewModel,它从 web 服务获取数据。数据结构为:
- 机器(有:Vehicles[])
- -Vehicles(有:名称、Cars[]、Trucks[]、...)----这就是我绑定到 lbMain 的内容
- --汽车(有:名称、颜色[]、...)----例如,颜色[0]="red"
- ---颜色值
我也有图片资源,我想放入 imgColor。
我不知道热到:
- 设置每个 imgColor 以根据 txtColor 从资源中获取不同的图像,
- 如果(例如)txtColor.Text="red",则对 txtCarName 应用粗体。
感谢任何意见和建议。
【问题讨论】:
标签: c# xaml windows-phone-7