StringFormat在Designer中显示错误,但在编译后不显示 - c#

我有一个带有MVVM的C#/ WPF程序。

Kalkulation.Artikel.PartWeightKalkulation.Artikel.SprueWeight均为小数。两者的格式均应具有一个可选的小数位和一千个分隔符。

我已经在下面的屏幕截图中实现了这一点。
StringFormat在Designer中显示错误,但在编译后不显示 - c#

对于每个StringFormat,我都会遇到三个错误:

Error   XLS0112 Expected ''.    Kalkulation MainWindow.xaml 113 
Error   XLS0414 The type '' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built. Kalkulation    MainWindow.xaml 113 
Error   XLS0112 Expected '

该图显示了Stackoverflow无法显示的标志。
StringFormat在Designer中显示错误,但在编译后不显示 - c#

当我编译时,我完全没有错误,一切都按预期工作!
当我更改XAML代码时,错误消息再次弹出。

我已关闭“显示文本框之间的同步”以轻松输入小数。 FrameworkCompatibilityPreferences.KeepTextBoxDisplaySynchronizedWithTextProperty = false;

我该怎么做才能改变这一点?我至少可以“过滤”错误消息吗?

参考方案

如果您已经有单引号并且仍然出现XLS0112 XAML错误,则可能缺少格式化请求{}前面的定界符{0:C0}

重新格式化会删除所有不需要定界符的前导文本,请务必小心!

好:

stringformat='Currency {0:C0}' // Proper string formatting

stringformat='{}{0:C0}' // Proper string formatting

坏:

stringformat='{0:C0}' // Functions but raises "XLS0112 XAML"

对数字变量使用'.ToString()' - c#

将数值转换为.ToString()时省略string有什么缺点吗?int i = 1234; string s; // Instead of s = "i is " + i.ToString(); // Writing s = "i is " + i; 参考方案 在这种情况下没有什么区别。"Count: &#…

WPF MVVM中的动态TabControl - c#

我几周前开始使用WPF(在C#中),现在我需要一些高级帮助来使用tabcontrol。首先,我正在使用MVVM(模型视图ViewModel)模式来设计我的应用程序,并且我有一个约束,即试图不要在文件(初始化xaml文件)后面的代码中添加代码。现在,我的问题是在MainWindow视图(窗口)中动态创建新的tabItem,当单击按钮(例如“新建选项卡”按钮)时…

将字符串分配给numpy.zeros数组[重复] - python

This question already has answers here: Weird behaviour initializing a numpy array of string data                                                                    (4个答案)         …

获取ListBoxItem的索引-WPF - c#

如何获取ListBoxItem的索引?ListBox通过XmlDataProvider绑定到XML节点的集合。 参考方案 我有一个类似的问题,得到了回答here基本上,您将ListBox的AlternationCount设置为非常高的值,并绑定到每个项目上的AlternationIndex<ListBox AlternationCount="…

TypeError:'str'对象不支持项目分配,带有json文件的python - python

以下是我的代码import json with open('johns.json', 'r') as q: l = q.read() data = json.loads(l) data['john'] = '{}' data['john']['use…