###前提・実現したいこと
動的に変化する文字列についてOSの言語によって日本語、英語に切り替えたいです。
静的な文字列(Buttonの名前等)であれば、日英ぞれぞれのResources.resxを用意して、
「データバインドを利用する」で設定できることは分かったのですが、
動的な文字列の場合の言語切り替え方法がわからず、悩んでいます。
サンプル実装を記載いたしました。
動的な文字列は
label.Content = m_Count + " 回押されました";
のように埋め込み文字列で実装しています。
これを実行して該当ボタンを押下すると、
日本語OSなら、
1回押されました。
英語OSなら
1 pushed.
みたいにしたいと考えています。
お手数ですが、ご教授お願いいたします。
###該当のソースコード
XAML
<Window x:Class="test111.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:test111" mc:Ignorable="d" Title="MainWindow" Height="187.255" Width="356.373"> <Grid> <Button x:Name="button" Content="ボタン1" HorizontalAlignment="Left" Margin="142,93,0,0" VerticalAlignment="Top" Width="75" Click="Button_Click"/> <Label x:Name="label" Content="" HorizontalAlignment="Left" Margin="85,21,0,0" VerticalAlignment="Top" Height="52" Width="235" FontSize="20"/> </Grid> </Window>
C#
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; namespace test111 { /// <summary> /// MainWindow.xaml の相互作用ロジック /// </summary> public partial class MainWindow : Window { private int m_Count = 0; public MainWindow() { InitializeComponent(); } private void Button_Click(object sender, RoutedEventArgs e) { m_Count++; label.Content = m_Count + " 回押されました"; // ←この動的文字列を言語切り替えしたい! } } }
###補足情報(言語/FW/ツール等のバージョンなど)
環境 Visual Studio 2013
回答4件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。