Domanda

Voglio creare un'applicazione WPF localizzabile AA.Ho seguito le istruzioni nei commenti del file AssemblyInfo.cs:

//In order to begin building localizable applications, set 
//<UICulture>CultureYouAreCodingWith</UICulture> in your .csproj file
//inside a <PropertyGroup>.  For example, if you are using US english
//in your source files, set the <UICulture> to en-US.  Then uncomment
//the NeutralResourceLanguage attribute below.  Update the "en-US" in
//the line below to match the UICulture setting in the project file.
.

Dopo averlo fatto, la mia applicazione non inizia più.Sto usando una classe di app personalizzata:

namespace Namespace
{
    public partial class App : Application
    {
        [STAThread()]
        [SecurityPermission(SecurityAction.LinkDemand)]
        public static void Main()
        {
            var app = new App();

            app.InitializeComponent();
            app.Run();
        }


        [DebuggerNonUserCode()]
        public void InitializeComponent()
        {
            this.StartupUri = new Uri("MainWindow.xaml", UriKind.Relative);
        }
    }
}
.

<ns:App
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:ns="clr-namespace:Namespace">

</ns:App>
.

Tutto ciò ha funzionato bene prima.Suppongo che ci sia una specie di mancata corrispondenza tra le impostazioni di uiccolo configurato e quella specificata per MainWindow.xaml, ma non so come risolverlo.

È stato utile?

Soluzione

Ho avuto un effetto simile;Nell'assembleaNFO.CS, l'attributo NeutralResourcesLanguage ha bisogno del parametro UltimateResourceFallbackLocation.Satellite:

// Uncommenting the following line --> OK
[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
// Uncommenting the following line --> IOException: Cannot locate resource 'app.xaml'.
// [assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.MainAssembly)]
// Uncommenting the following line --> IOException: Cannot locate resource 'app.xaml'.
// [assembly: NeutralResourcesLanguage("en-US")]
.

Altri suggerimenti

Alcune informazioni di base da: https://docs.microsoft.com/en-us/dotnet/Framework/WPF/Advanced/WPF-Globalization-and-localization-overview

Best practice per Localizzazione WPF

    .
  • Imposta la posizione UltimateResourceFallback in AssemblyInfo. * A Specificare la lingua appropriata per il fallback (ad esempio, [assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]).
  • Se decidi di includere la tua lingua di origine nell'assemblea principale di omettendo il tag <UICulture> nel tuo file di progetto, imposta il UltimateResourceFallback Posizione come assembly principale invece del Satellite (ad esempio, [assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.MainAssembly)])

.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top