我正在尝试通过菜单项更改语言。
我设法使用Combobox项做到了这一点,但是现在我不知道如何在MenuItems中做到这一点,知道吗?
public partial class MainWindow : Window
{
string strLanguage = "";
Boolean boolInit = true;
public MainWindow()
{
InitializeComponent();
boolInit = false;
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
Set_Language();
}
private void ddlLanguage_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
Set_Language();
}
private void Set_Language()
{
if (boolInit == false)
{
strLanguage = "SMS_Vrána.Languages." + ((ComboBoxItem)ddlLanguage.SelectedItem).Name.ToString();
ResourceManager LocRM = new ResourceManager(strLanguage, typeof(MainWindow).Assembly);
lblNumber.Text = LocRM.GetString("strNumber");
lblMessage.Text = LocRM.GetString("strMessage");
btnSend.Content = LocRM.GetString("strSend");
}
}
}
}
我的xaml
<DockPanel>
<Menu DockPanel.Dock="Top">
<MenuItem Header="_File">
<MenuItem Header="_test"/>
</MenuItem>
<MenuItem Header="_Language" Name="menuLangTest">
<MenuItem Header="Czech" Name="menuCzech"/>
<MenuItem Header="English" Name="menuEng"/>
</MenuItem>
</Menu>
</DockPanel>
<ComboBox Name="ddlLanguage" FontSize="22" SelectionChanged="ddlLanguage_SelectionChanged" Margin="10,77,10,301">
<ComboBoxItem IsEnabled="False" IsSelected="True">Language</ComboBoxItem>
<ComboBoxItem Name="English">English</ComboBoxItem>
<ComboBoxItem Name="Czech">Cesky</ComboBoxItem>
</ComboBox>
特别是单击菜单项时我不知道怎么说,请重命名文本标签。请寻求帮助。
我试图以此添加menuitem:
private void menuCzech_Click(object sender, RoutedEventArgs e)
{
strLanguage = "SMS_Vrána.Languages." + Name.ToString();
ResourceManager LocRM = new ResourceManager(strLanguage, typeof(MainWindow).Assembly);
lblNumber.Text = LocRM.GetString("strNumber");
lblMessage.Text = LocRM.GetString("strMessage");
btnSend.Content = LocRM.GetString("strSend");
}
不能解决我的问题。还是我做错了什么?