如何在 Silverlight 中绑定到 SystemColors?
我不确定什么是最好的技术。我在 App.xaml.cs 中设置了对系统颜色的引用。
App.Current.Resources.Add("ActiveBorderColor ", SystemColors.ActiveBorderColor);
并以这种方式绑定它:
<TextBlock Text="TextBlock" Foreground="{StaticResource ActiveBorderColor}" />
它可以工作,但我收到错误,无法解析“ActiveBorderColor”资源。这不是完美的解决方案。我想知道正确的方法是什么。任何想法都受到高度赞赏。谢谢。
I am not sure what will be the best techinique. I set references to system colors in App.xaml.cs.
App.Current.Resources.Add("ActiveBorderColor ", SystemColors.ActiveBorderColor);
and bind it this way:
<TextBlock Text="TextBlock" Foreground="{StaticResource ActiveBorderColor}" />
It works but I am getting error that the 'ActiveBorderColor' resource could not be resolved. It is not perfect solution. I am wondering what is the correct way to do it. Any ideas are highly appreciated. Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你想要做的是定义一个静态帮助器类。然后您可以通过引用它来通过 XAML 获取 SystemColors。我们在一个项目中这样做了,效果很好。这是一个简单的示例:
http://forums.silverlight.net/p/120976/289606。 aspx
请注意,Silverlight 版本的 SystemColors 类不会显示所有 SystemColors!与 WPF 中获得的内容相比,您会缺少一些内容。
(抱歉,花了这么长时间才意识到我的代码没有粘贴。请改为添加链接)
I think what you want to do is to define a static helper class. You can then get the SystemColors through XAML by referring to it. We did this on a project and it works well. Here's a quick example:
http://forums.silverlight.net/p/120976/289606.aspx
Be aware that the Silverlight version of the SystemColors class doesn't surface all the SystemColors! You'll be missing a few compared to what you get in WPF.
(sorry for taking so long to realize my code didn't paste. put in a link instead)