silverlight - 如何在 Silverlight 中正确组织 XAML 资源?

标签 silverlight xaml silverlight-4.0 resources

我的模块化应用程序中的资源文件存在一些问题。

我在这个 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/

相关文章:

wcf - 来自 Silverlight 的异步 WCF 调用

wpf - 有没有更好/更简洁的方式来声明这个重复的 WPF 绑定(bind)?

c# - 如何使用 C# xaml 以编程方式设置数据绑定(bind)

silverlight - 如何将 DataGrid 分组显示更改为其他聚合

sql - 将datetime2数据类型转换为datetime数据类型导致超出范围?

.net - 对于转向新技术的开发团队,您有什么建议?

silverlight - 标准 .Net 2 dll 是否与 silverlight 2.0 运行时兼容?

silverlight - 有没有办法以编程方式弹出 "Microsoft Silverlight Configuration"对话框?

Silverlight:如何将 List<T> 绑定(bind)到数据网格

android - 在 Xamarin Forms 中处理不同设备尺寸的缩放