views:

510

answers:

1

I need to create my silverlight framework that has all following features about resources.

  1. Partial loading. So, I can't use sample resource file(*.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.
  4. Easy to detect missing resources.

Hint

My framework is built on with Visual Studio Integration Package project. So, I can modify most of Visual Studio features like editor,toolbox, menu.

update#1

If it's impossible, So, I will create some resource edit on web server to manage this resource.

Thanks,

A: 

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 resources can be embeded within any XAML as all visual elements have a ResourceDictionary which is accessible via the Resources property.

<Grid>
    <Grid.Resources>        

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

    </Grid.Resources>
</Grid>

However, it is best practice to use special XAML files called "Resource Dictionaries".

<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.

<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.

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.

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. 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.
markti
Thanks. What's resource type that can be contained in Resource Dictionaries file. I think it's only stylesheet or relative uri. This idea like using simple resource file(*.resx).
Soul_Master
Any type can be stored in XAML. Some are easier than others to represent in XAML than others. If you want to embed binary files then you would simply add them to the project and mark them as resources to make them compile into the assembly.
markti