C#WPF以XAML样式指定文件夹
我有一个具有以下结构的项目:C#WPF以XAML样式指定文件夹,c#,wpf,xaml,resourcedictionary,C#,Wpf,Xaml,Resourcedictionary,我有一个具有以下结构的项目: Proj ├──Views ├ ├──Dashboard.xaml ├ ├──Dashboard.cs ├ ├──Styles ├──DashboardStyle.xaml 在我的DashboardStyle.xaml中,我有以下代码: <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xm
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>
....
....
但它给出了一个错误:
名称“Proj/Views/Dashboard”在命名空间“clr namespace:Proj.Styles”中不存在
如何解决此问题?使用名称空间和类型名称引用类型,而不是通过物理文件路径
因此,要引用类型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>
....
....
不应该本地是clr命名空间:项目视图
?然后,TargetType
变成了local:Dashboard
。但是我现在有另一个问题……我在同一个文件中还有标题栏按钮样式
。按钮正在获取样式,但悬停时不更改颜色,或正在单击。如果遇到其他问题,请提出其他问题。