How to properly organize XAML resources in Silverlight?

我的梦境 提交于 2019-12-07 19:32:51

问题


I'm having some issues with resource files in my modular application.

I have Infrastructure.DLL and some custom controls inside this DLL. Those controls using templates from themes/generic.xaml Issue that I have - Blend doesn't recognize those resources. Visual studio does.

Ideally I'd like to have styles for my cusom controls inside generic.xaml and styles for other controls somewhere else in common library that I can reference from my modules.

I also need Expression Blend and VS to work properly.

How do I arrange solution to make it happen?

PS. Important! WPF is different but I'm interested in Silverlight solution


回答1:


You just need to create design time resource for your generic.xaml in order to let Blend recoganize it. Take a look at this post.

In each of your modules, you create a ResourceDictionary like this.

    <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
        <ResourceDictionary.MergedDictionaries>
Source="/xxx.Silverlight.Controls;component/Themes/Generic.xaml" />
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>

Also, in your .csproj file, you need to add this. Please note that normally this piece of code is auto-generated by Blend, so if your ResourceDictionary is auto-generated, you don't need to do the following.

<Page Include="Design\DesignTimeResources.xaml" Condition="'$(DesignTime)'=='true' OR ('$(SolutionPath)'!='' AND Exists('$(SolutionPath)') AND '$(BuildingInsideVisualStudio)'!='true' AND '$(BuildingInsideExpressionBlend)'!='true')">
  <Generator>MSBuild:Compile</Generator>
  <SubType>Designer</SubType>
  <ContainsDesignTimeResources>true</ContainsDesignTimeResources>
</Page>

Design is the folder I created for storing my DesignTimeResources.xaml. I pretty much have the same structure as yours. :)



来源:https://stackoverflow.com/questions/8184264/how-to-properly-organize-xaml-resources-in-silverlight

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!