我在WPF XAML中有以下代码,并希望将其转换为Silverlight 4:
<Setter
Property="Background"
Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}" />
<Setter>不幸的是,Silverlight不支持x:Static。
有谁知道如何在没有代码隐藏的情况下正确地移植它,只支持XAML?
发布于 2010-12-09 22:22:26
因为你不能像那样访问静态属性,所以你必须定义自己的“包装器”类来包装静态属性,如下所示:
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>希望,这给了你一些想法。:-)
另请参阅以下内容:
https://stackoverflow.com/questions/4399104
复制相似问题