首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用UserControl.Resources

使用UserControl.Resources
EN

Stack Overflow用户
提问于 2012-01-25 11:27:40
回答 1查看 17.2K关注 0票数 2

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

我已经在论坛中搜索过了,但看起来我已经完全按照示例中的说明做了。不知何故,错误仍然存在,嵌入在资源中的样式无法应用到我的控件中。下面是我的代码:

代码语言:javascript
复制
<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>

请帮助:-(..

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-01-25 21:28:35

确保Resource.xaml的build操作设置为Page。

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

作为URI语法的示例,假设您的UserControl客户端位于一个名为NavigationControl的名称空间中,而该名称空间Client包含在一个名为App的名称空间中。如果应用程序将包含一个命名空间Resources,并且您的Resource.xaml将驻留在此命名空间中,那么正确的URI应该是../Resources/Resource.xaml。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8997476

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档