The requested page is not available for the requested platform. You are viewing the content for Default platform.

Resources in Mobile Applications

You can add custom resources - for example, localization dictionaries or themes - to your Mobile project's custom controls.

Mobile Resources Storages

The MobileResourcesHttpHandler<T> class searches for Mobile resources in the following locations (listed according to their priority).

  • A directory in a file system

    In the Mobile project's Web.config file, uncomment the auto-generated line with the XafMobileStaticFilesLocation key in the configuration section's appSettings element and set the value to the folder name to include this directory's resources in your application:

    <configuration> 
        <!-- ... -->
        <appSettings> 
            <!-- ... --> 
            <add key="XafMobileStaticFilesLocation" value="Static" /> 
        </appSettings> 
    </configuration>
    

    With this configuration, it searches the MySolution\MySolution.Mobile\Static folder.

    Note

    Set the Build Action property to Content for all files located in this folder.

    MobileCustomModules_BuiltAction

  • The DevExpress.ExpressApp.Mobile assembly

    This storage contains internal resources. You can modify these resources as described in the following Other assemblies part. However, only the resources containing the "Modules" substring in a file path can be modified.

  • Other assemblies

    To specify which XAF module should add its resources to the Mobile application, implement the IMobileResourcesHolder interface in the module's ModuleBase descendant and return the path to these resources in the GetMobileResourcesRelativePath method.

    Note
    • Use forward slashes in the path string.
    • Your resources files' Build Action property should be set to Embedded Resource.
    using DevExpress.ExpressApp;
    using DevExpress.ExpressApp.Mobile;
    //...
    public class MySolutionMobileModule : ModuleBase, IMobileResourcesHolder {
        //...
        public string GetMobileResourcesRelativePath() {
            return "MobileResources";  
        }
    }
    

    As a result, it searches for resources in the MySolution.Module.Mobile\MobileResources folder if your Mobile module is in the MySolution.Module.Mobile project.

How to Modify a Mobile Resource's Content at Runtime

To modify a Mobile resource's content at runtime, handle the MobileApplication.ModifyMobileResource event in the Mobile module's Setup method. In the event handler, use the ContentsAsString and Contents event arguments as shown below to replace existing content with a new string or a new byte array.

using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Mobile;
//...
public class MySolutionMobileModule : ModuleBase {
    //...
    public override void Setup(XafApplication application) {
        base.Setup(application);
        MobileApplication mobileApplication = (MobileApplication)application;
        //...
        mobileApplication.ModifyMobileResource += MobileApplication_ModifyMobileResource;
    }
    private void MobileApplication_ModifyMobileResource(object sender, ModifyMobileResourceEventArgs e) {
        if (e.Name.Contains("mysolution.module/hello.txt")) { 
           e.ContentsAsString = "\r\nconsole.log('hello from the modified file');"; 
        }
        if (e.Name.Contains("mysolution.module/customlogo.png")) { 
            byte[] oldArray = e.Contents; 
            byte[] newArray = new byte[oldArray.Length + 1]; 
            oldArray.CopyTo(newArray, 1); 
            newArray[0] = 20; 
            e.Contents = newArray; 
        } 
    }
}