我的模块化应用程序中的资源文件存在一些问题。
我在这个 DLL 中有 Infrastructure.DLL
和一些自定义控件。这些控件使用来自 themes/generic.xaml
的模板
我遇到的问题 - Blend 无法识别这些资源。 Visual Studio 可以。
理想情况下,我希望在 generic.xaml
中为我的自定义控件设置样式,在我可以从我的模块中引用的公共(public)库中的其他地方为其他控件设置样式。
我还需要 Expression Blend 和 VS 才能正常工作。
我如何安排解决方案来实现它?
附言。重要的! WPF 不同,但我对 Silverlight 解决方案感兴趣
最佳答案
您只需为您的 generic.xaml
创 build 计时资源,以便让 Blend 重新识别它。看看this post .
在您的每个模块中,您都像这样创建一个 ResourceDictionary
。
<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>
此外,在您的 .csproj
文件中,您需要添加此内容。请注意,通常这段代码是由 Blend 自动生成的,因此如果您的 ResourceDictionary
是自动生成的,则无需执行以下操作。
<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 是我创建的用于存储我的 DesignTimeResources.xaml
的文件夹。我的结构和你的差不多。 :)
关于silverlight - 如何在 Silverlight 中正确组织 XAML 资源?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8184264/