WPF - 使用带有电流绑定的转换器的正确语法
我有一个代表颜色的十六进制字符串的集合,并且我将组合框的 ItemsSource 绑定到该集合。
组合框项目被模板化为具有带有相关颜色的填充矩形。因此,我需要使用转换器将十六进制值转换为字符串。很容易。
然而,Blend 告诉我,这个语法在我的 XAML 中是不正确的:
Fill="{Binding, Converter={StaticResource StringToBrush}}"
显然,我不能对普通的旧“绑定”使用转换器。 Blend 说这样的东西在语法上是正确的:
Fill="{Binding Value, Converter={StaticResource StringToBrush}}"
...但是这显然不起作用。
我还不太熟悉绑定语法,所以显然我弄错了。
任何人都可以建议正确的语法来实现我想要做的事情(使用转换器 StringToBrush 转换我的绑定字符串)?
I have a collection of hex strings that represent colours and I am binding a combobox's ItemsSource to that collection.
The combobox items are templated to have a filled rectangle with the relevant colour. I therefore need to use a converter to convert the hex value to a string. Easy enough.
However, Blend is telling me that this syntax is incorrect in my XAML:
Fill="{Binding, Converter={StaticResource StringToBrush}}"
Apparently, I can't use a converter against plain old 'Binding'. Blend says that something like this is syntactically correct:
Fill="{Binding Value, Converter={StaticResource StringToBrush}}"
...However that obviously doesn't work.
I'm not quite au fait with binding syntax yet, so obviously I'm getting it wrong.
Can anyone advise the correct syntax to achieve what I'm trying to do (convert my bound String using the converter StringToBrush)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
收到了...发布后大约 3 分钟内。
我根本不需要逗号!
正确的语法是:
Fill =“{绑定转换器= {StaticResource StringToBrush}}”
Got it... within about 3 minutes of posting.
I simply didn't need the comma!
The correct syntax is:
Fill="{Binding Converter={StaticResource StringToBrush}}"