2008-08-28 74 views
4

如何引用xaml中類的靜態屬性?換句話說,我想要做這樣的事情:訪問XAML中的靜態字段

Class BaseThingy { 
    public static readonly Style BaseStyle; 
    ... 
} 
<ResoureDictionary ...> 
    <Style BasedOn="BaseThingy.Style" TargetType="BaseThingy" /> 
</ResourceDictionary> 

什麼是語法的支持算法FMP做到這一點?我認爲它會在某種程度上使用StaticResource,但我還沒有得到它爲我工作。

回答

11

使用x:Static標記擴展

<ResoureDictionary ... 
    xmlns:local="clr-namespace:Namespace.Where.Your.BaseThingy.Class.Is.Defined" 
> 
    <Style BasedOn="{x:Static local:BaseThingy.BaseStyle}" TargetType="BaseThingy" /> 
</ResourceDictionary> 
+1

我的印象是,`{X:靜...}在'沒有在Silverlight中工作。 – 2011-09-09 11:38:24