我在 WPF XAML 中有以下代码,并希望将其转换为 Silverlight 4:
<Setter
Property="Background"
Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}" />
<Setter>
遗憾的是,Silverlight 不支持 x:Static
。
有谁知道如何在没有代码隐藏、仅 XAML 的情况下正确移植它?
最佳答案
由于您无法访问这样的静态属性,因此您必须定义自己的“包装器”类来包装静态属性,如下所示:
public class StaticMemberAccess
{
public ResourceKey WindowBrushKey { return SystemColors.WindowBrushKey; }
//define other wrapper propeties here, to access static member of .Net or your classes
}
然后在 XAML 中执行此操作
<UserControl.Resources>
<local:StaticMemberAccess x:Key="SMA"/>
</UserControl.Resources>
<Setter
Property="Background"
Value="{Binding Source={StaticResource SMA}, Path=WindowBrushKey}" />
<Setter>
希望它能给你一些想法。 :-)
另请参阅:
关于silverlight - 绑定(bind)到 Silverlight XAML 中的 SystemColors,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4399104/