是否可以在转换器参数中使用 IValueConverter 的静态值?
在 Silverlight 中,我有一个标准 IValueConverter,我想将可能的参数定义为 const 字符串。
public class BooleanConverter : IValueConverter
{
public const string PARAMETER_ONE = "one";
public const string PARAMETER_TWO = "two";
...
然后我想在转换器参数中使用常量,例如:
<TextBlock Text="{Binding Name, Converter={StaticResource BooleanConverter},
ConverterParameter={StaticResource BooleanConvereter.PARAMETER_TWO}" />
这可能吗?如果是,正确的语法是什么?
In Silverlight, I have a standard IValueConverter where I want to define the possible parameters as const strings.
public class BooleanConverter : IValueConverter
{
public const string PARAMETER_ONE = "one";
public const string PARAMETER_TWO = "two";
...
I would then like to use the constant within the Converter Parameter, something like:
<TextBlock Text="{Binding Name, Converter={StaticResource BooleanConverter},
ConverterParameter={StaticResource BooleanConvereter.PARAMETER_TWO}" />
Is this possible? If yes, what is the correct syntax?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该能够使用静态标记扩展:
请注意,
x:Static
需要对类本身的引用,而不是对您的资源的引用。因此,您需要为其添加适当的 XML 命名空间前缀。You should be able to use the Static markup extension:
Note that the
x:Static
needs a reference to the class itself, not your resource. Therefore you'll need to prefix it with the appropriate XML namespace prefix.您可以同时使用参数和参数。示例:
转换器(包含参数和参数):
You can use both parameter and argument. Sample:
The Converter (contains both parameter and argument):