Silverlight XAML 绑定——十进制到双精度
我在 DataGridView 中有一些列,其 Binding 属性设置为如下所示:
Binding="{Binding NetPrice}"
问题是此 NetPrice 字段是 Decimal 类型,我想将其转换为 DataGrid 内的 Double 类型。
有什么方法可以做到这一点吗?
I've got some Columns in a DataGridView that have their Binding property set to something like the following:
Binding="{Binding NetPrice}"
The problem is that this NetPrice field is a Decimal type and I would like to convert it to Double inside the DataGrid.
Is there some way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我会创建一个转换器。转换器采用一个变量并将其“转换”为另一个变量。
有很多资源 用于创建转换器。它们也很容易在 C# 中实现并在 xaml 中使用。
您的转换器可能看起来与此类似:
创建转换器后,您将需要告诉您的 xaml 文件将其包含
在您的命名空间中(位于 xaml 的最顶部),如下所示:
然后声明静态资源,如下所示:
然后将其添加到您的绑定中,如下所示:
I would create a Converter. A converter takes one variable and "converts" it to another.
There are a lot of resources for creating converters. They are also easy to implement in c# and use in xaml.
Your converter could look similar to this:
Once you've created your converter, you will need to tell your xaml file to include it like this:
in your namespaces (at the very top of your xaml), include it like so:
Then declare a static resource, like so:
Then add it to your binding like this: