【发布时间】:2010-09-14 05:18:45
【问题描述】:
如何动态设置列表框中项目的背景颜色?即我的业务对象上也有一些属性,我也正在绑定,所以根据一些业务规则,我希望背景颜色不同?
<ListBox Background="Red">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="Background" Value="Red"/>
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal"
Margin="5">
<TextBlock VerticalAlignment="Bottom"
FontFamily="Comic Sans MS"
FontSize="12"
Width="70"
Text="{Binding Name}" />
<TextBlock VerticalAlignment="Bottom"
FontFamily="Comic Sans MS"
FontSize="12"
Width="70"
Text="{Binding Age}" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
编辑:上面写着here
在 Silverlight 中,您必须添加 x:Key 自定义样式的属性和 将它们作为静态资源引用。 Silverlight 不支持隐式 使用 TargetType 应用的样式 属性值。
这会影响我的方法吗?
【问题讨论】:
标签: silverlight