Risorse app per librerie destinate a più piattaformeApp Resources for Libraries That Target Multiple Platforms

È possibile utilizzare .NET Framework libreria di classi portabile tipo per assicurare che le risorse nelle librerie di classi è possibile accedere da più piattaforme di progetto.You can use the .NET Framework Portable Class Library project type to ensure that resources in your class libraries can be accessed from multiple platforms. Il tipo di progetto è disponibile in Visual Studio 2012Visual Studio 2012 e fa riferimento al subset portabile della libreria di classi di .NET Framework.This project type is available in Visual Studio 2012Visual Studio 2012 and targets the portable subset of the .NET Framework class library. Usando la Libreria di classi portabilePortable Class Library viene garantito che sia possibile accedere alla libreria da applicazioni desktop, applicazioni Silverlight, applicazioni Windows Phone e da applicazioni Windows 8.x StoreWindows 8.x Store.Using a Libreria di classi portabilePortable Class Library ensures that your library can be accessed from desktop apps, Silverlight apps, Windows Phone apps, and Windows 8.x StoreWindows 8.x Store apps.

Il progetto Libreria di classi portabilePortable Class Library crea solo un subset molto limitato dei tipi nello spazio dei nomi di System.Resources disponibile per l'applicazione, ma consente di usare la classe ResourceManager per recuperare le risorse.The Libreria di classi portabilePortable Class Library project makes only a very limited subset of the types in the System.Resources namespace available to your application, but it does allow you to use the ResourceManager class to retrieve resources. Tuttavia, se si crea un'applicazione tramite Visual Studio, è necessario usare il wrapper fortemente tipizzato creato da Visual Studio anziché usare la classe ResourceManager direttamente.However, if you are creating an app by using Visual Studio, you should use the strongly typed wrapper created by Visual Studio instead of using the ResourceManager class directly.

Per creare un wrapper fortemente tipizzato in Visual Studio, impostare il file di risorse principale modificatore di accesso in Progettazione risorse di Visual Studio per pubblica.To create a strongly typed wrapper in Visual Studio, set the main resource file's Access Modifier in the Visual Studio Resource Designer to Public. Ciò crea un file [resourceFileName].designer.cs o [resourceFileName].designer.vb che contiene il wrapper ResourceManager fortemente tipizzato.This creates a [resourceFileName].designer.cs or [resourceFileName].designer.vb file that contains the strongly typed ResourceManager wrapper. Per ulteriori informazioni sull'utilizzo di un wrapper di risorse fortemente tipizzata, vedere la sezione "Generazione di una classe fortemente tipizzata risorse" il Resgen.exe (Generatore di File di risorse) argomento.For more information about using a strongly typed resource wrapper, see the "Generating a Strongly Typed Resource Class" section in the Resgen.exe (Resource File Generator) topic.

Gestione risorse in Libreria di classi portabilePortable Class LibraryResource Manager in the Libreria di classi portabilePortable Class Library

In un progetto Libreria di classi portabilePortable Class Library, tutti gli accessi alle risorse sono gestiti dalla classe ResourceManager.In a Libreria di classi portabilePortable Class Library project, all access to resources is handled by the ResourceManager class. Poiché i tipi nello spazio dei nomi System.Resources, come ResourceReader e ResourceSet, non sono accessibili da un progetto Libreria di classi portabilePortable Class Library, non possono essere usati per accedere alle risorse.Because types in the System.Resources namespace, such as ResourceReader and ResourceSet, are not accessible from a Libreria di classi portabilePortable Class Library project, they cannot be used to access resources.

Il progetto Libreria di classi portabilePortable Class Library include i quattro membri ResourceManager elencati nella tabella seguente.The Libreria di classi portabilePortable Class Library project includes the four ResourceManager members listed in the following table. Questi costruttori e metodi consentono di creare un'istanza di un oggetto ResourceManager e recuperare le risorse di tipo stringa.These constructors and methods enable you to instantiate a ResourceManager object and retrieve string resources.

Membro ResourceManagerResourceManager member DescrizioneDescription
ResourceManager(String, Assembly) Crea un'istanza di ResourceManager per accedere al file di risorse denominato individuato nell'assembly specificato.Creates a ResourceManager instance to access the named resource file found in the specified assembly.
ResourceManager(Type) Crea un'istanza di ResourceManager che corrisponde al tipo specificato.Creates a ResourceManager instance that corresponds to the specified type.
GetString(String) Recupera una risorsa denominata per impostazioni cultura specifiche.Retrieves a named resource for the current culture.
GetString(String, CultureInfo) Recupera una risorse denominata per impostazioni cultura specifiche.Retrieves a named resource belonging to the specified culture.

L'esclusione di altri membri ResourceManager da Libreria di classi portabilePortable Class Library significa che oggetti serializzati, dati non di tipo stringa e immagini non possono essere recuperati da un file di risorse.The exclusion of other ResourceManager members from the Libreria di classi portabilePortable Class Library means that serialized objects, non-string data, and images cannot be retrieved from a resource file. Per usare le risorse da Libreria di classi portabilePortable Class Library, è necessario memorizzare tutti i dati oggetto in forma di stringa.To use resources from a Libreria di classi portabilePortable Class Library, you should store all object data in string form. Ad esempio, è possibile archiviare valori numerici in un file di risorse convertendoli in stringhe e recuperarli per poi riconvertirli in numeri usando il metodo Parse o TryParse del tipo di dati numerico.For example, you can store numeric values in a resource file by converting them to strings, and you can retrieve them and then convert them back to numbers by using the numeric data type's Parse or TryParse method. È possibile convertire immagini o altri dati binari in una rappresentazione di stringa chiamando il metodo Convert.ToBase64String e ripristinarli in una matrice di byte chiamando il metodo Convert.FromBase64String.You can convert images or other binary data to a string representation by calling the Convert.ToBase64String method, and restore them to a byte array by calling the Convert.FromBase64String method.

Libreria di classi portabilePortable Class Library e applicazioni Windows StoreThe Libreria di classi portabilePortable Class Library and Windows Store Apps

I progetti Libreria di classi portabilePortable Class Library archiviano le risorse in file .resx, che vengono quindi compilati in file .resources e incorporati nell'assembly principale o in assembly satellite in fase di compilazione.Libreria di classi portabilePortable Class Library projects store resources in .resx files, which are then compiled into .resources files and embedded in the main assembly or in satellite assemblies at compile time. Le applicazioni Windows 8.x StoreWindows 8.x Store, invece, richiedono che le risorse vengano archiviate nei file .resw, che vengono compilati in un singolo file di indice risorse (PRI).Windows 8.x StoreWindows 8.x Store apps, on the other hand, require resources to be stored in .resw files, which are then compiled into a single package resource index (PRI) file. Tuttavia, nonostante l'incompatibilità dei formati dei file, la Libreria di classi portabilePortable Class Library funzionerà in un'applicazione Windows 8.x StoreWindows 8.x Store.However, despite the incompatible file formats, your Libreria di classi portabilePortable Class Library will work in a Windows 8.x StoreWindows 8.x Store app.

Per usare la libreria di classi da un'applicazione Windows 8.x StoreWindows 8.x Store, aggiungere un riferimento al progetto di applicazione Windows Store.To consume your class library from a Windows 8.x StoreWindows 8.x Store app, add a reference to it in your Windows Store app project. Visual Studio estrarrà in modo trasparente le risorse dall'assembly in un file .resw e le userà per generare un file PRI da cui Windows RuntimeWindows Runtime potranno essere estratte le risorse.Visual Studio will transparently extract the resources from your assembly into a .resw file and use it to generate a PRI file from which the Windows RuntimeWindows Runtime can extract resources. In fase di esecuzione, Windows RuntimeWindows Runtime esegue il codice nella Libreria di classi portabilePortable Class Library, ma recupera le risorse della Libreria di classi portabile dal file PRI.At run time, the Windows RuntimeWindows Runtime executes the code in your Libreria di classi portabilePortable Class Library, but it retrieves your Portable Class Library's resources from the PRI file.

Se il progetto Libreria di classi portabilePortable Class Library include risorse localizzate, usare il modello hub and spoke per distribuirle proprio come avviene per una libreria in un'applicazione desktop.If your Libreria di classi portabilePortable Class Library project includes localized resources, you use the hub-and-spoke model to deploy them just as you would for a library in a desktop app. Per usare il file di risorse principale e qualunque file di risorse localizzate in un'applicazione Windows 8.x StoreWindows 8.x Store, aggiungere un riferimento all'assembly originale.To consume your main resource file and any localized resource files in your Windows 8.x StoreWindows 8.x Store app, you add a reference to the main assembly. In fase di compilazione, Visual Studio estrae le risorse dal file di risorse principale ed ogni file di risorse localizzate in file .resw separati.At compile time, Visual Studio extracts the resources from your main resource file and any localized resource files into separate .resw files. Vengono quindi compilate i file .resw in un singolo file PRI a cui Windows RuntimeWindows Runtime accede in fase di esecuzione.It then compiles the .resw files into a single PRI file that the Windows RuntimeWindows Runtime accesses at run time.

Esempio: Libreria di classi portabilePortable Class Library non localizzataExample: Non-Localized Libreria di classi portabilePortable Class Library

Il seguente semplice esempio di Libreria di classi portabilePortable Class Library non localizzata usa le risorse per archiviare i nomi delle colonne e per determinare il numero di caratteri da riservare ai dati tabulari.The following simple, non-localized Libreria di classi portabilePortable Class Library example uses resources to store the names of columns and to determine the number of characters to reserve for tabular data. Nell'esempio viene usato un file denominato LibResources.resx per archiviare le risorse di tipo stringa elencate nella tabella seguente.The example uses a file named LibResources.resx to store the string resources listed in the following table.

Nome della risorsaResource name Valore della risorsaResource value
BornBorn BirthdateBirthdate
BornLengthBornLength 1212
HiredHired Data assunzioneHire Date
HiredLengthHiredLength 1212
IDID IDID
ID.LengthID.Length 1212
NomeName NomeName
NameLengthNameLength 2525
TitoloTitle Employee DatabaseEmployee Database

Il codice seguente definisce un UILibrary classe che usa il wrapper di gestione risorse denominato resources generato da Visual Studio quando il modificatore di accesso per il file viene modificato in pubblica .The following code defines a UILibrary class that uses the Resource Manager wrapper named resources generated by Visual Studio when the Access Modifier for the file is changed to Public. La classe UILibrary analizza i dati della stringa, se necessario.The UILibrary class parses the string data as necessary. .. Notare che la classe si trova nello spazio dei nomi MyCompany.Employees.Note that the class is in the MyCompany.Employees namespace.

using System;
using System.Resources;
using MyCompany.Employees;

[assembly: NeutralResourcesLanguage("en-US")]

namespace MyCompany.Employees
{
   public class UILibrary
   {
      private const int nFields = 4;

      public static string GetTitle()
      {
         string retval = LibResources.Born; 
         if (String.IsNullOrEmpty(retval))
            retval = "";

         return retval;
      }

      public static string[] GetFieldNames()
      {
         string[] fieldnames = new string[nFields];
         fieldnames[0] = LibResources.Name;
         fieldnames[1] = LibResources.ID;
         fieldnames[2] = LibResources.Born;
         fieldnames[3] = LibResources.Hired;
         return fieldnames;
      }

      public static int[] GetFieldLengths()
      {
         int[] fieldLengths = new int[nFields];
         fieldLengths[0] = Int32.Parse(LibResources.NameLength);
         fieldLengths[1] = Int32.Parse(LibResources.IDLength);
         fieldLengths[2] = Int32.Parse(LibResources.BornLength);
         fieldLengths[3] = Int32.Parse(LibResources.HiredLength);
         return fieldLengths;
      }
   }
}
Imports System.Resources

<Assembly: NeutralResourcesLanguage("en-US")> 

Public Class UILibrary
   Private Const nFields As Integer = 4

   Public Shared Function GetTitle() As String
      Dim retval As String = My.Resources.LibResources.Title
      If String.IsNullOrEmpty(retval) Then retval = "<No value>"

      Return retval
   End Function

   Public Shared Function GetFieldNames() As String()
      Dim fieldnames(nFields - 1) As String
      fieldnames(0) = My.Resources.LibResources.Name
      fieldnames(1) = My.Resources.LibResources.ID
      fieldnames(2) = My.Resources.LibResources.Born
      fieldnames(3) = My.Resources.LibResources.Hired
      Return fieldnames
   End Function

   Public Shared Function GetFieldLengths() As Integer()
      Dim fieldLengths(nFields - 1) As Integer
      fieldLengths(0) = Int32.Parse(My.Resources.LibResources.NameLength)
      fieldLengths(1) = Int32.Parse(My.Resources.LibResources.IDLength)
      fieldLengths(2) = Int32.Parse(My.Resources.LibResources.BornLength)
      fieldLengths(3) = Int32.Parse(My.Resources.LibResources.HiredLength)
      Return fieldLengths
   End Function
End Class

Nell'esempio di codice riportato di seguito viene illustrato come sia possibile accedere alla classe UILibrary e alle relative risorse da una applicazione in modalità console.The following code illustrates how the UILibrary class and its resources can be accessed from a console-mode app. Richiede che venga aggiunto un riferimento a UILIbrary.dll al progetto di applicazione console.It requires a reference to UILIbrary.dll to be added to the console app project.

using System;
using System.Collections.Generic;
using MyCompany.Employees;
 
class Program
{
   static void Main()
   {
     // Get the data from some data source.
      var employees = InitializeData();

      // Display application title.
      string title = UILibrary.GetTitle();
      int start = (Console.WindowWidth + title.Length) / 2;
      string titlefmt = String.Format("{{0,{0}{1}", start, "}");
      Console.WriteLine(titlefmt, title);
      Console.WriteLine();

      // Retrieve resources.
      string[] fields = UILibrary.GetFieldNames();
      int[] lengths = UILibrary.GetFieldLengths();
      string fmtString = String.Empty;
      // Create format string for field headers and data.
      for (int ctr = 0; ctr < fields.Length; ctr++)
         fmtString += String.Format("{{{0},-{1}{2}{3}   ", ctr, lengths[ctr], ctr >= 2 ? ":d" : "", "}");

      // Display the headers.
      Console.WriteLine(fmtString, fields);
      Console.WriteLine();
      // Display the data.
      foreach (var e in employees)
         Console.WriteLine(fmtString, e.Item1, e.Item2, e.Item3, e.Item4);

      Console.ReadLine();
   }

   private static List<Tuple<String, String, DateTime, DateTime>> InitializeData() 
   {
      List<Tuple<String, String, DateTime, DateTime>> employees = new List<Tuple<String, String, DateTime, DateTime>>();
      var t1 = Tuple.Create("John", "16302", new DateTime(1954, 8, 18), new DateTime(2006, 9, 8));
      employees.Add(t1);
      t1 = Tuple.Create("Alice", "19745", new DateTime(1995, 5, 10), new DateTime(2012, 10, 17));
      employees.Add(t1);
      return employees;
   }
}
Imports MyCompany.Employees
Imports System.Collections.Generic

Module Module1

   Sub Main()
      ' Get the data from some data source.
      Dim employees = InitializeData()

      ' Display application title.
      Dim title As String = UILibrary.GetTitle()
      Dim start As Integer = (Console.WindowWidth + title.Length) \ 2
      Dim titlefmt As String = String.Format("{{0,{0}{1}", start, "}")
      Console.WriteLine(titlefmt, title)
      Console.WriteLine()

      ' Retrieve resources.
      Dim fields() As String = UILibrary.GetFieldNames()
      Dim lengths() As Integer = UILibrary.GetFieldLengths()
      Dim fmtString As String = String.Empty
      ' Create format string for field headers and data.
      For ctr = 0 To fields.Length - 1
         fmtString += String.Format("{{{0},-{1}{2}{3}   ", ctr, lengths(ctr), IIf(ctr >= 2, ":d", ""), "}")
      Next
      ' Display the headers.
      Console.WriteLine(fmtString, fields)
      Console.WriteLine()
      ' Display the data.
      For Each e In employees
         Console.WriteLine(fmtString, e.Item1, e.Item2, e.Item3, e.Item4)
      Next
      Console.ReadLine()
   End Sub

   Private Function InitializeData() As List(Of Tuple(Of String, String, Date, Date))
      Dim employees As New List(Of Tuple(Of String, String, Date, Date))
      Dim t1 = Tuple.Create("John", "16302", #8/18/1954#, #9/8/2006#)
      employees.Add(t1)
      t1 = Tuple.Create("Alice", "19745", #5/10/1995#, #10/17/2012#)
      employees.Add(t1)
      Return employees
   End Function
End Module

Il codice seguente mostra come sia possibile accedere alla classe UILibrary e alle relative risorse da un'applicazione Windows 8.x StoreWindows 8.x Store.The following code illustrates how the UILibrary class and its resources can be accessed from a Windows 8.x StoreWindows 8.x Store app. Richiede che venga aggiunto un riferimento a UILIbrary.dll al progetto di applicazione Windows Store.It requires a reference to UILIbrary.dll to be added to the Windows Store app project.

using System;
using System.Collections.Generic;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using MyCompany.Employees;

namespace ConsumerCS
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class BlankPage : Page
    {
        public BlankPage()
        {
            this.InitializeComponent();

         }

        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.  The Parameter
        /// property is typically used to configure the page.</param>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
           Example.DisplayData(outputBlock);
       }
    }
}

public class Example
{
    static public void DisplayData(Windows.UI.Xaml.Controls.TextBlock outputBlock)
    {
        // Get the data from some data source.
        var employees = InitializeData();
        outputBlock.FontFamily = new FontFamily("Courier New");      
        // Display application title.
        string title = UILibrary.GetTitle();
        outputBlock.Text += title + Environment.NewLine + Environment.NewLine;

        // Retrieve resources.
        string[] fields = UILibrary.GetFieldNames();
        int[] lengths = UILibrary.GetFieldLengths();
        string fmtString = String.Empty;
        // Create format string for field headers and data.
        for (int ctr = 0; ctr < fields.Length; ctr++)
            fmtString += String.Format("{{{0},-{1}{2}{3}   ", ctr, lengths[ctr], ctr >= 2 ? ":d" : "", "}");

        // Display the headers.
        outputBlock.Text += String.Format(fmtString, fields) + Environment.NewLine + Environment.NewLine;
        // Display the data.
        foreach (var e in employees)
            outputBlock.Text += String.Format(fmtString, e.Item1, e.Item2, e.Item3, e.Item4) + Environment.NewLine;
    }

    private static List<Tuple<String, String, DateTime, DateTime>> InitializeData()
    {
        List<Tuple<String, String, DateTime, DateTime>> employees = new List<Tuple<String, String, DateTime, DateTime>>();
        var t1 = Tuple.Create("John", "16302", new DateTime(1954, 8, 18), new DateTime(2006, 9, 8));
        employees.Add(t1);
        t1 = Tuple.Create("Alice", "19745", new DateTime(1995, 5, 10), new DateTime(2012, 10, 17));
        employees.Add(t1);
        return employees;
    }
}

Esempio: Libreria di classi portabilePortable Class Library localizzataExample: Localized Libreria di classi portabilePortable Class Library

Il seguente esempio di Libreria di classi portabilePortable Class Library localizzata include le risorse per le impostazioni cultura francesi (Francia) e inglesi (Stati Uniti).The following localized Libreria di classi portabilePortable Class Library example includes resources for the French (France) and English (United States) cultures. Le impostazioni cultura inglese (Stati Uniti) sono impostazioni cultura predefinite dell'app; le risorse vengono illustrate nella tabella di precedente sezione.The English (United States) culture is the app's default culture; its resources are shown in the table in the previous section. Il file di risorse per le impostazioni cultura francesi (Francia) è denominato LibResources.fr-FR.resx ed è costituito dalle risorse di tipo stringa elencate nella tabella seguente.The resources file for the French (France) culture is named LibResources.fr-FR.resx and consists of the string resources listed in the following table. Il codice sorgente per la classe UILibrary è lo stesso di quello riportato nella sezione precedente.The source code for the UILibrary class is the same as that shown in the previous section.

Nome della risorsaResource name Valore della risorsaResource value
BornBorn Date de naissanceDate de naissance
BornLengthBornLength 2020
HiredHired Date embauchéDate embauché
HiredLengthHiredLength 1616
IDID IDID
NomeName NomNom
TitoloTitle Base de données des employésBase de données des employés

Nell'esempio di codice riportato di seguito viene illustrato come sia possibile accedere alla classe UILibrary e alle relative risorse da una applicazione in modalità console.The following code illustrates how the UILibrary class and its resources can be accessed from a console-mode app. Richiede che venga aggiunto un riferimento a UILIbrary.dll al progetto di applicazione console.It requires a reference to UILIbrary.dll to be added to the console app project.

using System;
using System.Collections.Generic;
using System.Globalization;

using MyCompany.Employees;
 
class Program
{
   static void Main(string[] args)
   {
     
      // Get the data from some data source.
      var employees = InitializeData();

      // Display application title.
      string title = UILibrary.GetTitle();
      int start = (Console.WindowWidth + title.Length) / 2;
      string titlefmt = String.Format("{{0,{0}{1}", start, "}");
      Console.WriteLine(titlefmt, title);
      Console.WriteLine();

      // Retrieve resources.
      string[] fields = UILibrary.GetFieldNames();
      int[] lengths = UILibrary.GetFieldLengths();
      string fmtString = String.Empty;
      // Create format string for field headers and data.
      for (int ctr = 0; ctr < fields.Length; ctr++)
         fmtString += String.Format("{{{0},-{1}{2}{3}   ", ctr, lengths[ctr], ctr >= 2 ? ":d" : "", "}");

      // Display the headers.
      Console.WriteLine(fmtString, fields);
      Console.WriteLine();
      // Display the data.
      foreach (var e in employees)
         Console.WriteLine(fmtString, e.Item1, e.Item2, e.Item3, e.Item4);

      Console.ReadLine();
   }

   private static List<Tuple<String, String, DateTime, DateTime>> InitializeData() 
   {
      List<Tuple<String, String, DateTime, DateTime>> employees = new List<Tuple<String, String, DateTime, DateTime>>();
      var t1 = Tuple.Create("John", "16302", new DateTime(1954, 8, 18), new DateTime(2006, 9, 8));
      employees.Add(t1);
      t1 = Tuple.Create("Alice", "19745", new DateTime(1995, 5, 10), new DateTime(2012, 10, 17));
      employees.Add(t1);
      return employees;
   }

}
Imports MyCompany.Employees
Imports System.Collections.Generic
Imports System.Globalization
Imports System.Threading

Module Module1
   Sub Main()
      Dim culture As CultureInfo = CultureInfo.CreateSpecificCulture("fr-FR")
      Thread.CurrentThread.CurrentCulture = culture
      Thread.CurrentThread.CurrentUICulture = culture
      Console.WriteLine("Current culture is {0}", CultureInfo.CurrentCulture.Name)

      ' Get the data from some data source.
      Dim employees = InitializeData()

      ' Display application title.
      Dim title As String = UILibrary.GetTitle()
      Dim start As Integer = (Console.WindowWidth + title.Length) \ 2
      Dim titlefmt As String = String.Format("{{0,{0}{1}", start, "}")
      Console.WriteLine(titlefmt, title)
      Console.WriteLine()

      ' Retrieve resources.
      Dim fields() As String = UILibrary.GetFieldNames()
      Dim lengths() As Integer = UILibrary.GetFieldLengths()
      Dim fmtString As String = String.Empty
      ' Create format string for field headers and data.
      For ctr = 0 To fields.Length - 1
         fmtString += String.Format("{{{0},-{1}{2}{3}   ", ctr, lengths(ctr), IIf(ctr >= 2, ":d", ""), "}")
      Next
      ' Display the headers.
      Console.WriteLine(fmtString, fields)
      Console.WriteLine()
      ' Display the data.
      For Each e In employees
         Console.WriteLine(fmtString, e.Item1, e.Item2, e.Item3, e.Item4)
      Next
      Console.ReadLine()
   End Sub

   Private Function InitializeData() As List(Of Tuple(Of String, String, Date, Date))
      Dim employees As New List(Of Tuple(Of String, String, Date, Date))
      Dim t1 = Tuple.Create("John", "16302", #8/18/1954#, #9/8/2006#)
      employees.Add(t1)
      t1 = Tuple.Create("Alice", "19745", #5/10/1995#, #10/17/2012#)
      employees.Add(t1)
      Return employees
   End Function
End Module

Il codice seguente mostra come sia possibile accedere alla classe UILibrary e alle relative risorse da un'applicazione Windows 8.x StoreWindows 8.x Store.The following code illustrates how the UILibrary class and its resources can be accessed from a Windows 8.x StoreWindows 8.x Store app. Richiede che venga aggiunto un riferimento a UILIbrary.dll al progetto di applicazione Windows Store.It requires a reference to UILIbrary.dll to be added to the Windows Store app project. Usa la proprietà statica ApplicationLanguages.PrimaryLanguageOverride per impostare la lingua preferita dell'applicazione in francese.It uses the static ApplicationLanguages.PrimaryLanguageOverride property to set the app's preferred language to French.

using System;
using System.Collections.Generic;
using Windows.Globalization;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using MyCompany.Employees;

namespace LocConsumerCS
{
    public sealed partial class BlankPage : Page
    {
        public BlankPage()
        {
            this.InitializeComponent();

        }

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            Example.Demo(outputBlock);
        }
    }

    public class Example
    {
        public static void Demo(TextBlock outputBlock)
        {
            // Set the application preferences.
            ApplicationLanguages.PrimaryLanguageOverride = "fr-FR";

            // Get the data from some data source. 
            var employees = InitializeData();
            outputBlock.FontFamily = new FontFamily("Courier New");
            // Display application title.
            string title = UILibrary.GetTitle();
            outputBlock.Text += title + Environment.NewLine + Environment.NewLine; 

            // Retrieve resources.
            string[] fields = UILibrary.GetFieldNames();
            int[] lengths = UILibrary.GetFieldLengths();
            string fmtString = String.Empty;
            // Create format string for field headers and data.
            for (int ctr = 0; ctr < fields.Length; ctr++)
                fmtString += String.Format("{{{0},-{1}{2}{3}   ", ctr, lengths[ctr], ctr >= 2 ? ":d" : "", "}");

            // Display the headers.
            outputBlock.Text += String.Format(fmtString, fields) + Environment.NewLine + Environment.NewLine;

            // Display the data.
            foreach (var e in employees)
                outputBlock.Text += String.Format(fmtString, e.Item1, e.Item2, e.Item3, e.Item4) + Environment.NewLine;
        }

        private static List<Tuple<String, String, DateTime, DateTime>> InitializeData()
        {
            List<Tuple<String, String, DateTime, DateTime>> employees = new List<Tuple<String, String, DateTime, DateTime>>();
            var t1 = Tuple.Create("John", "16302", new DateTime(1954, 8, 18), new DateTime(2006, 9, 8));
            employees.Add(t1);
            t1 = Tuple.Create("Alice", "19745", new DateTime(1995, 5, 10), new DateTime(2012, 10, 17));
            employees.Add(t1);
            return employees;
        }
    }
}
Imports Windows.Globalization
Imports MyCompany.Employees

Public NotInheritable Class BlankPage
    Inherits Page

    Protected Overrides Sub OnNavigatedTo(e As Navigation.NavigationEventArgs)
        Example.Demo(outputBlock)
    End Sub
End Class

Public Class Example
    Public Shared Sub Demo(outputBlock As Windows.UI.Xaml.Controls.TextBlock)
        ' Set the application preferences.
        ApplicationLanguages.PrimaryLanguageOverride = "fr-FR"

        ' Get the data from some data source. 
        Dim employees = InitializeData()
        outputBlock.FontFamily = New FontFamily("Courier New")
        ' Display application title.
        Dim title As String = UILibrary.GetTitle()
        outputBlock.Text += title + vbCrLf + vbCrLf

        ' Retrieve resources.
        Dim fields() As String = UILibrary.GetFieldNames()
        Dim lengths() As Integer = UILibrary.GetFieldLengths()
        Dim fmtString As String = String.Empty
        ' Create format string for field headers and data.
        For ctr = 0 To fields.Length - 1
            fmtString += String.Format("{{{0},-{1}{2}{3}   ", ctr, lengths(ctr), If(ctr >= 2, ":d", ""), "}")
        Next
        ' Display the headers.
        outputBlock.Text += String.Format(fmtString, fields) + vbCrLf + vbCrLf

        ' Display the data.
        For Each e In employees
            outputBlock.Text += String.Format(fmtString, e.Item1, e.Item2, e.Item3, e.Item4) + vbCrLf
        Next
    End Sub

    Private Shared Function InitializeData() As List(Of Tuple(Of String, String, Date, Date))
        Dim employees As New List(Of Tuple(Of String, String, Date, Date))
        Dim t1 = Tuple.Create("John", "16302", #8/18/1954#, #9/8/2006#)
        employees.Add(t1)
        t1 = Tuple.Create("Alice", "19745", #5/10/1995#, #10/17/2012#)
        employees.Add(t1)
        Return employees
    End Function
End Class

Vedere ancheSee Also

ResourceManager
Risorse nelle applicazioni desktopResources in Desktop Apps
Creazione del pacchetto e distribuzione delle risorsePackaging and Deploying Resources