これは非常に簡単な質問かもしれないので、私の申し訳ありません。WPFページ要素へのプロパティの継承
ここで私の問題は、C#を使って多言語のWPF
アプリケーションを構築したいのですが、別のPage
要素を同じ方法で継承させる方法がわかりませんから、MainWindowを別の言語に翻訳します。アプリは完了しました。私はただ英語(私の母国語はスペイン語)に翻訳しています。 私はそれを翻訳するのにResource files
を使用しています。言語翻訳のための
コード:今すぐ
private void Languages_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
//This is the combobox in which you select the language to display the app in
Set_Language();
}
//This is the method to invoke the Resource Manager and all the stuff from the resource file.
private void Set_Language()
{
if (!boolInit)
{
strLanguage = "LeitProjekteV2._0.Languages." + ((ComboBoxItem)LanguageSel.SelectedItem).Name.ToString();
ResourceManager LocRm = new ResourceManager(strLanguage, typeof(MainWindow).Assembly);
//Menu buttons
lblMenu.Content = LocRm.GetString("strMainMenu"); //The names inside the "" are the names of the resource in the Resource file which, depending on the language selected(Spanish, English and German)
//Change the text of whatever I choose; in this case, a Label named 'lblMenu'
MapButt.Content = LocRm.GetString("strMapButt");
BuscButt.Content = LocRm.GetString("strBusButt");
AgeButt.Content = LocRm.GetString("strAgeButt");
ComButt.Content = LocRm.GetString("strComButt");
InfButt.Content = LocRm.GetString("strInfButt");
LoginButt.Header = LocRm.GetString("strLoginButt");
RegisterButt.Header = LocRm.GetString("strRegisterButt");
ContacButt.Header = LocRm.GetString("strContacButt");
MasButt.Header = LocRm.GetString("strMoreButt");
//Here go the names of everything the Pages contain that I want to translate, just like above
//Have no idea how to inherit this method to all the pages
}
}
あなたはbutton
「地図」、Frame
をクリックするように、私は、同じMainWindow.xaml
に埋め込まれpages
いくつかを持っていることが名前のPage
にコンテンツによる変更Map.xamlなど、他のボタンについても同様です。 しかし、どうすればそれらをPages
も翻訳できますか?
Set_Language()メソッドが正しいResource File
を選択するためにCombobox
の文字列値を取るので、それは私の問題を排除するにもかかわらず、私は、私が持っているすべてのPage
のための1つのコンボボックスを作成する必要はありません。
助けが必要ですか?恐ろしいことを聞いて申し訳ありませんが、私はまだここでヒントを得ています。
ありがとうございました。以下
これは本当に有望に見えますが、私が戻ったときに間違いなく試してみましょう。ありがとう! –