■ ResourceManager 클래스의 GetString 메소드를 사용해 다국어 문자열을 설정하는 방법을 보여준다.
▶ MainApplication.xaml.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
using System.Globalization; using System.Windows; namespace TestProject { /// <summary> /// 메인 애플리케이션 /// </summary> public partial class MainApplication : Application { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainApplication() /// <summary> /// 생성자 /// </summary> public MainApplication() { // 영문 적용시 주석을 해제한다. //CultureInfo cultureInfo = new CultureInfo("en-US"); // //CultureInfo.DefaultThreadCurrentCulture = cultureInfo; //CultureInfo.DefaultThreadCurrentUICulture = cultureInfo; } #endregion } } |
▶ MainWindow.xaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
<Window x:Class="TestProject.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Width="800" Height="600" Title="TestProject" FontFamily="나눔고딕코딩" FontSize="16"> <Grid> <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center"> <TextBox Name="textBlock1" HorizontalAlignment="Center" /> <TextBox Name="textBlock2" Margin="0 10 0 0" HorizontalAlignment="Center" /> </StackPanel> </Grid> </Window> |
▶ MainWindow.xaml.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
using System.Reflection; using System.Resources; using System.Windows; namespace TestProject { /// <summary> /// 메인 윈도우 /// </summary> public partial class MainWindow : Window { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainWindow() /// <summary> /// 생성자 /// </summary> public MainWindow() { InitializeComponent(); ResourceManager resourceManager = new ResourceManager ( "TestProject.LOCALIZATION.Resource", Assembly.GetExecutingAssembly() ); this.textBlock1.Text = resourceManager.GetString("KEY1"); this.textBlock2.Text = resourceManager.GetString("KEY2"); } #endregion } } |