Is there any way to convert the members of a collection used as an ItemsSource?

后端 未结 3 760
醉话见心
醉话见心 2020-12-17 15:59

In WPF you can use an IValueConverter or IMultiValueConverter to convert a data-bound value from say an int to a Color.

I have a collection

3条回答
  •  庸人自扰
    2020-12-17 16:51

    You cannot set the converter on the collection itself, because it would get the collection as input. You have two choices:

    1. Make sure your converter can also deal with collections (IEnumerable).
    2. Use the converter within the item template.

    If you want to use the second approach, then use something like this:

    
      
        
          
        
      
    
    

    If you don't need a custom datatemplate, then you can skip the ContentTemplate attribute.

提交回复
热议问题