[英]Binding ComboBox SelectedItem to double
My ComboBox's ItemsSource
is binding to a List<double> options
and the SelectedItem
is binding to a property double SelectedOption
. 我的ComboBox的ItemsSource
绑定到List<double> options
, SelectedItem
绑定到属性double SelectedOption
。
If options
contains the values 0.0060F, 0.0075F, 0.0100F
and SelectedItem = 0.0060F
, the ComboBox does should, but does not, reflect this. 如果options
包含值0.0060F, 0.0075F, 0.0100F
和SelectedItem = 0.0060F
,则ComboBox应该但不会反映这一点。 Instead, selecting the ComboBox shows the options
list items with their strange decimal representations. 相反,选择ComboBox会显示带有奇怪的十进制表示的options
列表项。 Is it even possible to do data binding on variables of type double
with their unpredictable representation? 甚至可以使用不可预测的表示形式对double
类型的变量进行数据绑定吗?
Code 码
ViewModel: 视图模型:
//Properties
public List<double> Options{get;set;}
public double SelectedOption{get;set;}
//Constructor
public ViewModel()
{
Options = new List<double>();
Options.Add(0.0060F);
Options.Add(0.0075F);
Options.Add(0.0100F);
SelectedOption = 0.0060F;
}
Binding: 捆绑:
<ComboBox ItemsSource="{Binding Path=Options}"
SelectedItem="{Binding Path=SelectedOption, Mode=TwoWay}" />
The options that are shown in the ComboBox are: ComboBox中显示的选项是:
Maybe you should give a read at what floating points are: http://csharpindepth.com/Articles/General/FloatingPoint.aspx 也许你应该读一下浮点数: http : //csharpindepth.com/Articles/General/FloatingPoint.aspx
Those values are used to give a as close as possible to reality representation of numbers. 这些值用于尽可能接近数字的现实表示。 If you want exact values, use System.Decimal 如果需要精确值,请使用System.Decimal
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.