如何在 Silverlight 中正确组织 XAML 资源? [英] How to properly organize XAML resources in Silverlight?

查看:44
本文介绍了如何在 Silverlight 中正确组织 XAML 资源?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的模块化应用程序中的资源文件有一些问题.

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

我在这个 DLL 中有 Infrastructure.DLL 和一些自定义控件.那些使用来自 themes/generic.xaml 的模板的控件我遇到的问题 - Blend 无法识别这些资源.Visual Studio 可以.

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.

理想情况下,我希望在 generic.xaml 中为我的自定义控件设置样式,并在公共库中的其他位置设置其他控件的样式,以便我可以从我的模块中引用.

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.

我还需要 Expression Blend 和 VS 才能正常工作.

I also need Expression Blend and VS to work properly.

我如何安排解决方案以实现它?

How do I arrange solution to make it happen?

附注.重要的!WPF 不同,但我对 Silverlight 解决方案很感兴趣

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

推荐答案

您只需要为您的 generic.xaml 创建设计时资源,以便让 Blend 识别它.看看 这篇文章.

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.

在您的每个模块中,您都可以像这样创建一个 ResourceDictionary.

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>

此外,在您的 .csproj 文件中,您需要添加此项.请注意,这段代码通常是由 Blend 自动生成的,因此如果您的 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 是我创建的文件夹,用于存储我的 DesignTimeResources.xaml.我和你的结构几乎一样.:)

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

这篇关于如何在 Silverlight 中正确组织 XAML 资源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆