<UserControl.Resources>
<DataTemplate x:Key="MyCustomTemplate">
<StackPanel Orientation="Horizontal">
<Label Content="{Binding Path=ID}"/>
<Rectangle Height="18" Width="20" />
</StackPanel>
</DataTemplate>
</UserControl.Resources>
<Grid>
<ListBox x:Name="userListBox" Margin="10"/>
</Grid>
代码后面:绑定矩形填充到一个值
userListbox.ItemsSource = myservice.getvalue();
现在我该如何绑定矩形的颜色。 getValue返回一个成员为整数的对象列表,我必须使用该值来决定矩形的颜色。 说,如果object.item = 1种颜色=绿色 object.item = 2颜色=红色
你想交替行的颜色,或者你只是想col0r基于属性值的矩形? – 2010-10-04 06:15:29