Collection views are about sorting, filtering, grouping. They are not about data transformation.
Actually, there's no direct need in such collection in your task interpretation. You just need to set up view properly, e.g. providing correct DataTemplate
for items in your source collection:
public class MyEntity
{
public int Id { get; set; }
public string Name { get; set; }
}
public class MyViewModel
{
public ObservableCollection<MyEntity> Entities { get; private set; }
public ICollectionView EntitiesView
{
if (view == null)
{
view = new ListCollectionView(Entities);
}
return view;
}
private ICollectionView view;
}
XAML:
<DataTemplate DataType="{x:Type local:MyEntity}">
<!-- This "transforms" visual representation of your entity, but the entity itself (and its container) remains unchanged -->
<TextBlock Text="{Binding Name}"/>
</DataTemplate>
Update.
According to you comment, I'd wrap entities into view models. Moreover, this is a purpose of view models:
public class MyEntityViewModel
{
private readonly MyEntity model;
public MyEntityViewModel(MyEntity model)
{
this.model = model;
}
public int MyInt
{
get { return model. // some logic to retrieve int ... }
}
public string MyString
{
get { return model. // some logic to retrieve string ... }
}
}
Then, instead of collection of models, I'd bind the control to the collection of view models:
public class MyViewModel
{
public MyViewModel(ICollection<MyEntity> entities)
{
this.Entities = new ObservableCollection<MyEntityViewModel>(entities.Select(e => new MyEntityViewModel(e)));
// this will keep two collections synchronized:
this.Entities.CollectionChanged += (sender, args) =>
{
switch (e.Action)
{
case NotifyCollectionChangedAction.Add:
entities.Add((MyEntity)e.NewItems[0]);
break;
case NotifyCollectionChangedAction.Remove:
entities.Remove((MyEntity)e.OldItems[0]);
break;
case NotifyCollectionChangedAction.Replace:
entities.Remove((MyEntity)e.OldItems[0]);
entities.Add((MyEntity)e.NewItems[0]);
break;
case NotifyCollectionChangedAction.Reset:
entities.Clear();
break;
}
}
}
public ObservableCollection<MyEntityViewModel> Entities { get; private set; }
}
This will keep your data class clear from extra properties, which are intended for view only.