Visual Studio 2010 - 字典未找到但存在

时间:2011-10-14 13:29:09

标签: wpf visual-studio xaml resourcedictionary

好吧,我正在开发一个wpf应用程序,我在设计时遇到了一个奇怪的错误。这是wpf格式的代码:

<Window x:Class="ViewLayer.Frm_EnrollWaitingList"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Frm_EnrollWaitingList" WindowStartupLocation="CenterScreen" BorderBrush="{x:Null}" mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" Height="390" Width="410"
        WindowStyle="None"
        AllowsTransparency="True"
        ResizeMode="NoResize">
    <Window.Resources>
        <ResourceDictionary Source="Dictionary/WaitingListDictorionary.xaml"/>
    </Window.Resources>
    <Grid>
        <Rectangle Margin="0,0,0,0" Name="rectangle1" Stroke="{x:Null}" Fill="#FF8C90AD" Opacity="0.95" />
        <Button Style="{DynamicResource CommonButton}" Content="Salir" Height="80" HorizontalAlignment="Left" Margin="166,234,0,0" Name="btn_close" VerticalAlignment="Top" Width="180" />
    </Grid>
</Window>

问题从这里开始:

<Window.Resources>
    <ResourceDictionary Source="Dictionary/WaitingListDictorionary.xaml"/>
</Window.Resources>

ResourceDictionary退出并在执行时间内完美运行。但在设计时,有时想要在visual studio designer中修改表单时会出现以下错误:

FileNotFoundException An error occurred while finding the resource dictionary "Dictionary/WaitingListDictorionary.xaml".


Unable to find the specified file.
   at Microsoft.Windows.Design.Platform.ViewProducerBase.Microsoft.Expression.DesignModel.DocumentModel.IDocumentRootResolver.GetDocumentRoot(String path)
   at Microsoft.Expression.Platform.WPF.InstanceBuilders.ResourceDictionaryInstanceBuilder.ProvideResourceDictionary(IInstanceBuilderContext context, DocumentCompositeNode resourceDictionaryReferenceNode, IDocumentRoot& relatedRoot)

我无法使用设计师编辑表单。

有什么想法吗?我重复执行时间,我没有问题。

2 个答案:

答案 0 :(得分:1)

Source属性是相对的,您的窗口似乎位于ViewLayer目录中,因此如果您使用

Dictionary文件夹也必须位于ViewLayer目录中
Source="Dictionary/WaitingListDictorionary.xaml".  

如果Dicionary文件夹位于根级别,请尝试

Source="/Dictionary/WaitingListDictorionary.xaml".

您还可以使用pack:// URL。

答案 1 :(得分:-1)

我能搞清楚!

我试图使用ResourceDictionary时出错。我修好了,瞧!一切都像魅力一样。