在使用一个类库在 WPF 中开发图形界面的过程中,我遇到了一个问题:我不明白如何将 Configuration 对象作为静态资源绑定到图形界面的元素上。
写道:
<Window.Resources>
<Configuration x:Key="config"/>
</Window.Resources>
但这不会编译,尽管配置在 C# 代码中是完全可见的,但在标记中却没有。
我试图xmlns:lib通过类比来描述命名空间xmlns:local
<Window x:Class="GUI.MainWindow"
<…>
xmlns:local="clr-namespace:GUI"
xmlns:lib="clr-namespace:ClassLibrary">
尽管如此,仍显示两个错误:
XDG0008: The name "Configuration" does not exist in the namespace "clr-namespace:ClassLibrary".XLS0414: The type 'lib:Configuration' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built.
如何解决?
您只需要指定定义命名空间的程序集的名称,如下所示:
在那之后,一切都应该工作。
来源:微软(WPF XAML 的 XAML 命名空间和命名空间映射)