我在使用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>请帮助:-(..
发布于 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。
https://stackoverflow.com/questions/8997476
复制相似问题