我有一个具有以下结构的项目:
Proj
├──Views
├ ├──Dashboard.xaml
├ ├──Dashboard.cs
├
├──Styles
├──DashboardStyle.xaml
在我的
DashboardStyle.xaml
中,我有以下代码:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Proj.Styles">
<Style x:Key="MyWindowStyle" TargetType="local:Proj/Views/Dashboard">
....
....
</Style>
</ResourceDictionary>
但它给出了错误:
命名空间“clr-namespace:Proj.Styles”中不存在名称“Proj/Views/Dashboard”
如何解决这个问题?
类型是使用命名空间和类型名称引用的,而不是通过物理文件路径。
因此,要引用类型
Proj.Views.Dashboard
,请将相应的命名空间添加为 XML 命名空间声明,并在 TargetType 属性中使用它,例如
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Proj.Styles"
xmlns:views="clr-namespace:Proj.Views" >
<Style x:Key="MyWindowStyle" TargetType="views:Dashboard">
....
....
</Style>
</ResourceDictionary>
感谢您的简洁帮助! 还有一个麻烦是使用 Visual Studio XAML IDE,即即使上述所有内容都是正确的,Intellisense 仍然会抱怨,例如在上述情况下,将是:- 错误XDG0008,名称……命名空间中不存在…… 需要一个新的构建来解决这个问题!