XAML非常简单:
<TabItem Header="Year 1 Correlations" Name="tabItem_Correlations"
Style="{DynamicResource LabelStyle}">
<Grid>
<DataGrid AutoGenerateColumns="True" Name="CorrelationsGrid"
IsReadOnly="True" ItemsSource ="{Binding Path=ViewCorrelations}"/>
</Grid>
</TabItem>
传入的数据是一个非常简单的DataTable.DefaultView,其中列以相关系列命名。
当我查看绑定背后的数据时 - 两列都有预期的数据。但在实际界面中,只有不带数字0.25的列显示数据。
我可以通过以下方式避免这种情况:
series.Replace(".", "DOT")
在将列名添加到DataTable之前:
瞧,瞧!我想解决方案是避免小数位,但有人可以解释原因吗?或者我只是在密集......
答案 0 :(得分:1)
.
(Dot)在内部被绑定表达式用作属性路径分隔符。
假设您想要与A类的某个属性B绑定,您可以使用点分隔符绑定它:
"{Binding Path=A.B}"
因此,在您的案例 Credit Spreads-GBP-0.25-AAA
内部,绑定引擎正在25-AAA
中寻找属性Credit Spreads-GBP-0
。
如果查看Visual Studio的输出窗口,您将看到相同的错误:
无法使用绑定检索值,也没有有效的回退值 存在;使用默认值。 BindingExpression:路径=信用 传播-GBP-0.25-AAA;的DataItem =&#39; NamedObject&#39; (的HashCode = 18874777); 目标元素是&#39; TextBlock&#39; (名称=&#39;&#39);目标属性是&#39; Text&#39; (键入&#39; String&#39;)
此外,您可以自己验证。挂钩AutoGeneratingColumns
事件和处理程序检查属性路径。
private void dg_AutoGeneratingColumn(object sender,
DataGridAutoGeneratingColumnEventArgs e)
{
DataGridTextColumn textColumn = (DataGridTextColumn)e.Column;
var propertyPath = ((Binding)textColumn.Binding).Path.Path;
// propertyPath will be Credit Spreads-GBP-0.25-AAA in your case.
}