당신이 할 : 여기
가능한 옵션 중 일부입니다 이를 달성하기 위해 마크 업 확장이 필요하지 않습니다. 당신은 간단한 ValueConverter로 그것을 할 수 있습니다.
는 ("문자열 1"값이라는 문자열 값으로, 우리는 Resource1.resx을 호출 할이 예를 들어, "안녕하세요 세계!") 프로젝트에의 .resx 파일을 추가
변환기를 만드는 것이 문자열을 현지화 된 문자열로 변환합니다.
namespace WpfApplication1.Converters
{
public class ResxLocalizationConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
string result = Resource1.ResourceManager.GetString(value.ToString());
if (result == null)
{
result = value.ToString();
}
return result;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
- 는 컨버터 인스턴스가
<Application x:Class="WpfApplication1.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="Window1.xaml"
xmlns:converters="clr-namespace:WpfApplication1.Converters">
<Application.Resources>
<converters:ResxLocalizationConverter x:Key="ResxLocalizationConverter" />
</Application.Resources>
</Application>
이 XAML에서 지역화되지 않은 문자열 값 (또는 키)를 넣어 App.xaml에 추가.
<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Grid>
<TextBlock Text="{Binding Source='String1', Converter={StaticResource ResxLocalizationConverter}}"/>
</Grid>
</Window>
이에 "Hello World!"를 표시합니다 TextBlock에서.
예를 들어 프랑스어로 지역화하려면 Resource1.fr-FR.resx를 Visual Studio 프로젝트에 추가해야합니다 ("String1"값 "Salut tout le monde!"라는 문자열 값 사용). 프랑스어 버전의 PC에 프랑스어 버전이 표시되거나 명시 적으로 언어를 선택할 수있는 ResourceManager.GetString (...) 오버로드를 사용할 수 있습니다.
XAML 리소스를 사용하여 지역화 할 수도 있습니다 –