No me gusta usar ReadOnlyObservableCollection<T>
ya que parece un error/clase rota; Prefiero un enfoque basado en contrato en su lugar.
Esto es lo que yo uso que permite covarience:
public interface INotifyCollection<T> : ICollection<T>, INotifyCollectionChanged
{
}
public interface IReadOnlyNotifyCollection<out T> : IReadOnlyCollection<T>, INotifyCollectionChanged
{
}
public class NotifyCollection<T> : ObservableCollection<T>, INotifyCollection<T>, IReadOnlyNotifyCollection<T>
{
}
public class Program
{
private static void Main(string[] args)
{
var full = new NotifyCollection<string>();
var readOnlyAccess = (IReadOnlyCollection<string>) full;
var readOnlyNotifyOfChange1 = (IReadOnlyNotifyCollection<string>) full;
//Covarience
var readOnlyListWithChanges = new List<IReadOnlyNotifyCollection<object>>()
{
new NotifyCollection<object>(),
new NotifyCollection<string>(),
};
}
}
Bienvenido a Stackoverflow y felicidades a su primera respuesta. Intente que sea más fácil de comprender, por ejemplo, formateando (Código, párrafos separados o estilos de lista). Tal vez un ejemplo ayudaría? – Mateng