APLICACIÓN WPF MULTIIDIOMA

Add / New Item / Resource Dictionary (WPF) à Strings.xaml
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:system="clr-namespace:System;assembly=mscorlib">

    <system:String x:Key="ResourceDictionaryName">Loc-en-US</system:String>
    <system:String x:Key="Price">Price</system:String>
    <system:String x:Key="Quantity_short">Qty.</system:String>
    <system:String x:Key="Discount_short">Disc.</system:String>
   
</ResourceDictionary>

Add / New Item / Resource Dictionary (WPF) à Strings.es-ES.xaml
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:system="clr-namespace:System;assembly=mscorlib">

    <system:String x:Key="ResourceDictionaryName">Loc-es-ES</system:String>
    <system:String x:Key="Price">Precio</system:String>
    <system:String x:Key="Quantity_short">Cant.</system:String>
    <system:String x:Key="Discount_short">Desc.</system:String>
   
</ResourceDictionary>

En XAML de la pantalla à
<Button x:Name="btPrice" Content="{DynamicResource Price}">
<Button x:Name="btQty" Content="{DynamicResource Quantity_short}"
<Button x:Name="btDisc" Content="{DynamicResource Discount_short}">

Crear la función para detectr el idioma del equipo y llamarla en Loadded de la pantalla principal del programa à
Private Sub SetLanguageDictionary()
        Dim dict As New ResourceDictionary()
        Select Case System.Threading.Thread.CurrentThread.CurrentCulture.ToString()
            Case "es-ES"
                dict.Source = New Uri("Multilanguage\Strings.es-ES.xaml", UriKind.Relative)
                Exit Select
            Case Else
                dict.Source = New Uri("Multilanguage\Strings.xaml", UriKind.Relative)
                Exit Select
        End Select
        Me.Resources.MergedDictionaries.Add(dict)
       

  End Sub

No hay comentarios:

Publicar un comentario