WPF databinding to interface and not actual object - casting possible?

前端 未结 6 1475
时光取名叫无心
时光取名叫无心 2020-11-27 05:27

Say I have an interface like this:

public interface ISomeInterface
{
...
}

I also have a couple of classes implementing this interface;

6条回答
  •  情深已故
    2020-11-27 06:01

    The short answer is DataTemplate's do not support interfaces (think about multiple inheritance, explicit v. implicit, etc). The way we tend to get around this is to have a base class things extend to allow the DataTemplate specialization/generalization. This means a decent, but not necessarily optimal, solution would be:

    public abstract class SomeClassBase
    {
    
    }
    
    public class SomeClass : SomeClassBase
    {
    
    }
    
    
        
    
    

提交回复
热议问题