Wpf 使用UserControl.Resources

Wpf 使用UserControl.Resources,wpf,xaml,user-controls,Wpf,Xaml,User Controls,我在使用UserControl.Resources时遇到一些问题。我不断遇到错误消息“文件'Resources\Resource.xaml'不是项目的一部分,或者其'Build Action'属性未设置为'Resource' 我已经在论坛中搜索过了,但看起来我已经完全完成了示例中所述的操作。不知何故,错误仍然存在,并且资源中嵌入的样式未能应用到我的控件中。以下是我的代码: <UserControl x:Class="Client.NavigationControl"

我在使用UserControl.Resources时遇到一些问题。我不断遇到错误消息“文件'Resources\Resource.xaml'不是项目的一部分,或者其'Build Action'属性未设置为'Resource'

我已经在论坛中搜索过了,但看起来我已经完全完成了示例中所述的操作。不知何故,错误仍然存在,并且资源中嵌入的样式未能应用到我的控件中。以下是我的代码:

<UserControl x:Class="Client.NavigationControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:local="clr-namespace:Client"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             HorizontalAlignment="Left"
             VerticalAlignment="Top"
             d:DesignHeight="59"
             d:DesignWidth="349"
             mc:Ignorable="d">

<UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="Resources\Resource.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
 </UserControl.Resources>

<Grid Name="grid1"
          Width="341"
          Height="54"
          HorizontalAlignment="Stretch"
          VerticalAlignment="Stretch">


 <Button Name="button2"
                Width="97"
                Height="35"
                Margin="106,10,0,0"
                HorizontalAlignment="Left"
                VerticalAlignment="Top"
                Command="{Binding ButtonResponseSection}"
                CommandParameter="ResponseSection"
                Content="ResponseSection"
                Style="{DynamicResource GlassButton}" />


    </Grid>
</UserControl>


请帮助:-(..

确保Resource.xaml的生成操作设置为第页

此外,请查看您的相对URI“Resources\Resource.xaml”是否正确


作为URI语法的一个示例,假设您的UserControl NavigationControl位于名为Client的命名空间中,而命名空间客户端包含在名为App的命名空间中。如果App将包含命名空间资源,而Resource.xaml将驻留在此命名空间中,则正确的URI将为../Resources/Resource.xaml。

对不起因为我不太理解你关于“你的项目文件看起来像”?的问题…谢谢你的回答!我已经把资源的引用放在App.xaml中了,现在它可以工作了!非常感谢!