wpf - 如果此列的标题包含点,为什么我无法设置 datagrid 单元格值?
问题描述
我的 wpf app xaml 很简单,只有一个数据网格:
<DataGrid ItemsSource="{Binding UserCollection}"/>
在后面的代码中,UserCollection 是一个 DataTable:
private DataTable userCollection;
public DataTable UserCollection
{
get { return this.userCollection; }
set
{
this.userCollection = value;
NotifyPropertyChanged();
}
}
在 ViewModel.cs 中,代码很简单,创建 2 列并添加一行:
this.UserCollection = new DataTable();
UserCollection.Columns.Add("col1", typeof(int));
UserCollection.Columns.Add("co.l2", typeof(int));
var r=UserCollection.NewRow();
r["col1"] = 1;
r["co.l2"] = 2;
UserCollection.Rows.Add(r);
但是听者中包含点的第 2 列无法在 UI 中显示该值,您可以看到图片。
为什么?
解决方案
我找到了解决方案,使用以下方法将 dot char 替换为另一个 char:
StringNameWithDot.Replace(".", "\x2024");
Wpf 数据表列标题不能包含“.”、“/”、“[]”,这是另一个链接:
推荐阅读
- python - python - 从列表中构造嵌套字典
- excel - 如何在工作簿(但不是 ActiveWorkbook)中获取选定的选项卡?
- angular - Angular 2+ textarea 占位符条件和翻译
- java - JComboBox 将与泛型类型数组列表一起使用吗?
- c# - 代理服务器 vs 主机文件 vs 防火墙,哪个以编程方式阻止 C# 中的网站?
- ios - UITableViewCell 只有在某个区域被按下时才会被选中
- pentaho - PDI 中“生成行”步骤中的变量
- angular - 角,量角器,黄瓜问题
- mysql - 在我的 sql 中加入两个表不返回结果集
- powershell - Powershell:通过将脚本指向功能列表来添加 WindowsFeature