ListBoxコントロール

 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 [マナ]

コメント:



(画像の文字列を入力して下さい)

トップ   編集 凍結 差分 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2019/12/02 (月) 12:41:39 (1627d)

G|Cg|C@Amazon Yahoo yV

z[y[W yVoC[UNLIMITȂ1~] COiq COsیI