<Window.Resource>
<ResourceDictionary>
<local:SomeResourceWithObsCollection x:Key="MyItemWithCollection">
<local:SomeClass.Instance /> <!-- THIS DOES NOT WORK -->
</local:SomeResourceWithObsCollection>
</ResourceDictionary>
</Window.Resources>
我不知道如何让这条线路工作...我试过做<x:Static SomeClass.Instance />
,但这也是不允许的。带静态项目的XAML资源?
[ContentProperty("TheItems")]
public class SomeResourceWithObsCollection
{
public class SomeResourceWithObsCollection()
{
TheItems = new ObservableCollection<IMyInterface>();
}
public ObservableCollection<IMyInterface> TheItems { get; set; }
}
public class SomeClass : IMyInterface
{
private static SomeClass _instance = new SomeClass();
private SomeClass() { }
public SomeClass Instance { get { return _instance; } }
}
你在* *试图得到它呢?你可以发布“SomeResourceWithObsCollection”类型的细节吗? –
我发布了实际上是相关的东西。基本上我有单身实例。如果我删除这些项目是单身的事实,一切正常。但是,我想基本上能够在XAML中使用单例实例。 – michael