silverlight 3 中动态改变listboxitem背景色,拖动滚动条颜色会错乱,bug?
<ListBox x:Name="playlist">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding title}" TextWrapping="Wrap" Margin="3,0,0,0"></TextBlock>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
var playlistNowItem = playlist.ItemContainerGenerator.ContainerFromIndex(i) as ListBoxItem;
playlistNowItem.Background = new SolidColorBrush(Colors.Black);
playlistNowItem.Foreground = new SolidColorBrush(Colors.Green);
改变了某一条的background颜色之后看着正常,然后上下胡乱拖动右侧的滚动条,发现会有别的listboxitem也变色,再胡乱拖动,又出现错乱的listboxitem又了...
这是咋回事???
[解决办法]
你修改了ItemTemplate,应用后,应该不是仅一条背景。
你可以参考这篇文章修改
http://timheuer.com/blog/archive/2010/02/04/changing-datagrid-selected-row-state.aspx?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+timheuer+%28Method+%7E+of+%7E+failed+by+Tim+Heuer%29
[解决办法]
不如尝试用ScrollView自定义下拉列表代替listBox