简体   繁体   English

在Silverlight中管理资源的最佳方法是什么?

[英]What's the best idea to manage resources in Silverlight?

I need to create my silverlight framework that has all following features about resources. 我需要创建一个具有关于资源的所有以下功能的Silverlight框架。

  1. Partial loading. 部分加载。 So, I can't use sample resource file(*.resx). 因此,我不能使用示例资源文件(* .resx)。
  2. Strongly-typed resource file. 类型强的资源文件。 Because It's very easy to debug. 因为它非常容易调试。
  3. Easy to edit with sample text editor. 易于使用示例文本编辑器进行编辑。 Because you can't use some complex editor like visual studio in web server. 因为您不能在Web服务器中使用像Visual Studio这样的复杂编辑器。
  4. Easy to detect missing resources. 易于检测丢失的资源。

Hint 暗示

My framework is built on with Visual Studio Integration Package project. 我的框架是使用Visual Studio集成包项目构建的。 So, I can modify most of Visual Studio features like editor,toolbox, menu. 因此,我可以修改大多数Visual Studio功能,例如编辑器,工具箱,菜单。

update#1 更新#1

If it's impossible, So, I will create some resource edit on web server to manage this resource. 如果不可能,那么,我将在Web服务器上创建一些资源编辑以管理该资源。

Thanks, 谢谢,

I'm not sure what you are trying to do as your question was rather vague, but I can shed some light on how resources can be managed on the Silverlight platform. 我不确定您要做什么,因为您的问题相当模糊,但是我可以阐明如何在Silverlight平台上管理资源。

Silverlight resources can be embeded within any XAML as all visual elements have a ResourceDictionary which is accessible via the Resources property. 可以将Silverlight资源嵌入任何XAML中,因为所有可视元素都具有ResourceDictionary,可通过Resources属性访问该资源。

<Grid>
    <Grid.Resources>        

        <DataTemplate x:Key="MyTemplate">
        </DataTemplate>

    </Grid.Resources>
</Grid>

However, it is best practice to use special XAML files called "Resource Dictionaries". 但是,最佳实践是使用称为“资源字典”的特殊XAML文件。

<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >

    <DataTemplate x:Key="MyTemplate">
    </DataTemplate>

</ResourceDictionary>

Silverlight 3, brings the ability to automatically merge these resource dictionaries into the application's main resource dictionary. Silverlight 3具有自动将这些资源字典合并到应用程序的主资源字典中的功能。

<Application.Resources>
    <ResourceDictionary>

        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="Resources/A.xaml"/>
            <ResourceDictionary Source="Resources/B.xaml"/>
            <ResourceDictionary Source="Resources/C.xaml"/>
        <ResourceDictionary.MergedDictionaries>
    <ResourceDictionary>
<Application.Resources>

In order to merge a resource dictionary with your Application's resources, the resource dictionaries must reside within the compressed XAP package that is used to deploy Silverlight applications down to the client. 为了将资源字典与应用程序的资源合并,资源字典必须驻留在用于将Silverlight应用程序向下部署到客户端的压缩XAP包中。

However, if you wanted to, you could store the XAML resource dicationaries on the web server and bring them into your Silverlight application by using WebClient to download the file, then using XamlReader to construct the object model in memory from the XAML string you retrieve from the file. 但是,如果愿意,可以使用WebClient下载文件,然后使用XamlReader根据从中检索的XAML字符串在内存中构造对象模型,从而将XAML资源文档存储在Web服务器上并将它们带入Silverlight应用程序。文件。

Resource dictionaries are inherently strongly typed but not type-safe . 资源字典本质上是强类型的,但不是类型安全的 In that, you will not get a compile time error if you have an improperly typed element in XAML. 这样,如果XAML中键入的元素不正确,则不会出现编译时错误。 If there happens to be an error in one of your resources you will find out only when a reference to it is initialized and the rendering engine attempts to instantiate your resource. 如果您的其中一个资源发生错误,则只有在对其的引用被初始化并且渲染引擎尝试实例化您的资源时,您才会发现错误。

So in short: 简而言之:

  1. Yes. 是。
  2. Yes. 是。
  3. Yes. 是。
  4. No. 没有。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 管理一个人的会话变量的最佳方法是什么? - What is the best way to manage one's session variables? 什么是Silverlight插件? - What's a Silverlight plugin? 在Team Foundation Server 2010中,ASP.NET MVC 2,Silverlight 4和WPF的最佳托管是什么? - What's the best hosting for ASP.NET MVC 2, Silverlight 4 and WPF with Team Foundation Server 2010? ASP.NET:管理全球资源的最佳方式? - ASP.NET: Best way to manage global resources? 在ASP.NET网站的ActiveDirectory中管理角色的最佳方法是什么? - What is the best way to manage roles in ActiveDirectory for ASP.NET Website? REST API管理字段的最大字符数的最佳实践是什么? - What is the best practice for a REST api to manage maximum characters for a field? 在ASP.NET 2.0中管理设置(配置)的最佳方法是什么? - What is the best way to manage settings (configuration) in ASP.NET 2.0? 在ASP.NET MVC中管理用户的最佳方法是什么 - What is the best way to manage users in ASP.NET MVC 在Web应用程序中管理DataCacheFactory对象的最佳方法是什么? - What is the best way to manage the DataCacheFactory object in a web application? 在asp.net中管理全局变量的最佳方法是什么? - What is the best way to manage Global variable in asp.net?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM