DataGridのようなListBoxの奇数行の背景もカスタマイズできます。 <UserControl.Resources> <c:MyConverter x:Key="myconverter"></c:MyConverter> </UserControl.Resources> <ListBox x:Name="ListBox1" Width="500" Height="300"> <ListBox.ItemTemplate> <DataTemplate> <StackPanel Width="500" Background="{Binding Converter={StaticResource myconverter}}"> <TextBlock Text="{Binding age}"></TextBlock> </StackPanel> </DataTemplate> </ListBox.ItemTemplate> </ListBox> using System.Windows.Data public class MyConverter : IValueConverter { bool flag = false; SolidColorBrush brush1 = new SolidColorBrush(Color.FromArgb(255, 100, 200, 255)); SolidColorBrush brush2 = new SolidColorBrush(Color.FromArgb(255, 200, 100, 155)); public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { flag = !flag; return flag ? brush1 : brush2; } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } ウィジェット型CM動画配信サービス manna [マナ] コメント: |