Silverlight 中的 Setter.Value 代替 Setter

发布于 2024-08-06 04:08:12 字数 436 浏览 2 评论 0原文

我知道我可以像这样在 Silverlight 中编写 Setter:

<Setter Property="Background" Value="{StaticResource MyBrush}" />

但是,由于其他考虑,我必须以以下格式编写 setter:

<Setter Property="Background">
  <Setter.Value>
      ????? static resource
  </Setter.Value>
</Setter>

我见过的任何示例都将值设置为完整画笔,但我想使用现有的资源,不知道怎么写。它不仅仅是画笔,我在一般概念上遇到了麻烦,试图找出正确的属性类型来尝试并为其设置值。有什么建议吗?

杰夫

I know I can write a Setter in Silverlight like this:

<Setter Property="Background" Value="{StaticResource MyBrush}" />

However, due to other considerations, I have to write the setter in the format:

<Setter Property="Background">
  <Setter.Value>
      ????? static resource
  </Setter.Value>
</Setter>

Any examples I've seen have the value set as the full brush but I want to use an existing resource and I don't know how to write it. Its not just brushes, I'm having trouble with the concept in general trying to work out the right type of property to try and set the value for. Any tips?

Jeff

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

顾挽 2024-08-13 04:08:12

由 {XXX} 表示的任何标记扩展都可以写为。这里,{StaticResource MyBrush} 实际上创建了一个 StaticResourceExtension 类型的对象,并将“MyBrush”作为其构造函数的唯一参数传递,构造函数本身设置了该对象的 ResourceKey 属性。您可以通过使用以下方法达到相同的效果:

<StaticResource ResourceKey="MyBrush" />

如果您不知道属性是什么类型,只需将插入符号设置在您感兴趣的属性上,然后按 F1 打开 Visual Studio 中的帮助,它应该为您提供信息你正在寻找。

Any markup extension, denoted by {XXX} can be written as <XXX>. Here, {StaticResource MyBrush} is in fact creating an object of type StaticResourceExtension, passing "MyBrush" as the only argument of its constructor, which itself sets the ResourceKey property of the object. You can achieve the same effect by using:

<StaticResource ResourceKey="MyBrush" />

If you don't know what type a property is, simply set your caret on the property you're interested in and press F1 to open the help in Visual Studio which should provides you with the information you're seeking.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文