Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#WPF以XAML样式指定文件夹_C#_Wpf_Xaml_Resourcedictionary - Fatal编程技术网

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
。但是我现在有另一个问题……我在同一个文件中还有标题栏按钮样式
。按钮正在获取样式,但悬停时不更改颜色,或正在单击。如果遇到其他问题,请提出其他问题。