WPF绑定双精度值 [英] WPF Binding Double Value

查看:95
本文介绍了WPF绑定双精度值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,亲爱的

当我们绑定属性时,有没有一种方法可以在xaml中进行舍入处理?

is there a way to make rounding process in xaml when we bind the attribute??

EX:我有一个值5.156845,我想在绑定属性时将其四舍五入到5.16

EX: I have a value 5.156845 I want to round it to 5.16 when I bind the attribute

推荐答案

绑定时,您绑定到一个财产.  在属性的设置器中(当您在UI中更改值时会调用它),您可以执行所需的任何操作,例如在将值分配给属性的后备字段之前将其四舍五入.
When you bind you bind to a property.  In the setter of the property (it gets called when you change the value in the UI) you can do what ever you want such as rounding the value before assigning it to the backing field for the property.


这篇关于WPF绑定双精度值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆