是否可以让 WPF/SL4 对绑定到另一个控件的属性执行操作?
使用 SilverLight,可以将控件的值绑定到数据上下文中的属性。没关系。
可以将 StringFormat 与绑定声明一起使用来格式化该值。再说一次,那太酷了!
但是,我找不到一种方法可以在显示之前对其进行一些操作的绑定。我知道我可以编写 IConverter,但我一直在寻找纯粹在 XAML 中的东西(如果存在的话)。我还可以向类添加一个属性,以正确的方式返回数据,但是如果您没有该类的源代码,仍然会发生什么情况?
例如,假设我的数据上下文有这个类(通过通知等正确设置):
public class Info
{
public int SomeValue {...} // Value from 0 to 15
}
我想要一个显示 45 而不是 15 的绑定,其中绑定将被声明为类似 {Binding SomeValue, Operation= "*3"}
.NET 世界中是否有类似的东西(来自 MSoft 或 OpenSource)?
Using SilverLight, one can bind the value of a control to a property from a datacontext. That's fine.
It is possible to use StringFormat along with the binding declaration to format the value. Again, that's cool!
However, I can't find a way to have the binding with some operation done to it before it gets displayed. I know I can code an IConverter but I was looking for something purely in XAML if that exists. I could also add a property to the class that returns the data in the correct way, but still what would happen if you don't have the source of the class?
For example, let's say I have this class for my datacontext (properly setup with notification and the like):
public class Info
{
public int SomeValue {...} // Value from 0 to 15
}
I would like to have a binding that would display 45 instead of 15 where the binding would be declared something like {Binding SomeValue, Operation="*3"}
Is there something like this in the .NET world (either from MSoft or OpenSource)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
找到链接 我正在谈论。
尽管如此,Charles Petzold 也建议宁可使用 ValueConverter,即使在纯 XAML 中可以进行某些算术运算
found the link I was talking about.
Still, Charles Petzold also suggest to rather use a ValueConverter, even though some arithmetics is possible in pure XAML