开发者

VS2010 designer not working when the ResourceDictionary is in a subfolder

I have a project which contains the entry point of my application and a ResourceDictionary. In a first time, these files were located at the root of the project. At this time, I could see all the components (button for exemple) modified by the style in the designer of xaml files in other projects.

Now, I have subfolders like this : src/launcher which contains my entry point and src/styles which contains my ResourceDictionary. But now, the components are not styled in the designer of VS2010. The program compiles and works well, but the designer doesn't work. I get the "Cannot find the resource ..." error constantly. The code of my main xaml file is :

<Application x:Class="MANAGER.Program"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             Startup="Application_Startup">
    <Application.Resources>
        <ResourceDictionary Source="../Styles/Style.xaml"></ResourceDicti开发者_C百科onary>
    </Application.Resources>
</Application>

Why the designer doesn't work ?


Your code should look this way in order to use subdirectories out of your application root directory:

<Application x:Class="MANAGER.Program"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             Startup="Application_Startup">
    <Application.Resources>
        <ResourceDictionary Source="pack://siteoforigin:,,,../Styles/Style.xaml"></ResourceDictionary>
    </Application.Resources>
</Application>


It might have something to do with the format of the "Source" attribute. The format needs to be a Pack URI like "pack://siteoforigin:,,,/SiteOfOriginFile.xaml"

Have a look at these documentations in MSDN:

  • ResourceDictionary.Source Property

  • Packet URIs in WPF

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜