开发者

Binding to SystemColors in Silverlight XAML

开发者 https://www.devze.com 2023-01-29 11:07 出处:网络
I have follow开发者_C百科ing code in WPF XAML and want it to be converted to Silverlight 4: <Setter

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

精彩评论

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

关注公众号