[英]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框架。
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: 简而言之:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.