开发者

Binding to SystemColors in Silverlight XAML

I have follow开发者_C百科ing code in WPF XAML and want it to be converted to Silverlight 4:

<Setter
    Property="Background"
    Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}" />
<Setter>

Unfortunately, Silverlight does not support x:Static.

Does anybody know how to port it properly without code behind, XAML-only?


Since you cannot access Static properties like that,you've to define your own "wrapper" class that will wrap the static properties, something like this:

public class StaticMemberAccess
{
      public ResourceKey WindowBrushKey { return SystemColors.WindowBrushKey; }
      //define other wrapper propeties here, to access static member of .Net or your classes
}

Then do this in XAML

<UserControl.Resources>
   <local:StaticMemberAccess x:Key="SMA"/>
</UserControl.Resources>

<Setter
    Property="Background"
    Value="{Binding Source={StaticResource SMA}, Path=WindowBrushKey}" />
<Setter>

Hope, it gives you some idea. :-)

See this also:

Retrieving value from static extension XAML

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜