Changing language using menu items in C# wpf












0















I am trying to change language through menu items.



I managed to do that using Combobox items but now I don't know how to make it in MenuItems, any idea?



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");
}
}
}


}



mine 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>


Specially what I don't know how to say if menuitem is clicked rename text labels.. Ty for any help.



I tried to add menuitem as this:



        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");
}


Not solving my problem. Or am I doing something wrong?










share|improve this question

























  • Possible duplicate of In WPF how to add menu item event?

    – ASh
    Nov 23 '18 at 13:54











  • It is not, I can't add event like that. It is not working for me, i was trying it already.

    – Lukáš Vrábel
    Nov 23 '18 at 14:39











  • try strLanguage = "SMS_Vrána.Languages." + (sender as MenuItem).Header.ToString();

    – ASh
    Nov 23 '18 at 14:51











  • @ASh Thats not it.. Not working for me..

    – Lukáš Vrábel
    Nov 26 '18 at 7:57
















0















I am trying to change language through menu items.



I managed to do that using Combobox items but now I don't know how to make it in MenuItems, any idea?



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");
}
}
}


}



mine 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>


Specially what I don't know how to say if menuitem is clicked rename text labels.. Ty for any help.



I tried to add menuitem as this:



        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");
}


Not solving my problem. Or am I doing something wrong?










share|improve this question

























  • Possible duplicate of In WPF how to add menu item event?

    – ASh
    Nov 23 '18 at 13:54











  • It is not, I can't add event like that. It is not working for me, i was trying it already.

    – Lukáš Vrábel
    Nov 23 '18 at 14:39











  • try strLanguage = "SMS_Vrána.Languages." + (sender as MenuItem).Header.ToString();

    – ASh
    Nov 23 '18 at 14:51











  • @ASh Thats not it.. Not working for me..

    – Lukáš Vrábel
    Nov 26 '18 at 7:57














0












0








0








I am trying to change language through menu items.



I managed to do that using Combobox items but now I don't know how to make it in MenuItems, any idea?



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");
}
}
}


}



mine 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>


Specially what I don't know how to say if menuitem is clicked rename text labels.. Ty for any help.



I tried to add menuitem as this:



        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");
}


Not solving my problem. Or am I doing something wrong?










share|improve this question
















I am trying to change language through menu items.



I managed to do that using Combobox items but now I don't know how to make it in MenuItems, any idea?



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");
}
}
}


}



mine 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>


Specially what I don't know how to say if menuitem is clicked rename text labels.. Ty for any help.



I tried to add menuitem as this:



        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");
}


Not solving my problem. Or am I doing something wrong?







c# wpf menuitem






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 '18 at 14:43







Lukáš Vrábel

















asked Nov 23 '18 at 13:28









Lukáš VrábelLukáš Vrábel

115




115













  • Possible duplicate of In WPF how to add menu item event?

    – ASh
    Nov 23 '18 at 13:54











  • It is not, I can't add event like that. It is not working for me, i was trying it already.

    – Lukáš Vrábel
    Nov 23 '18 at 14:39











  • try strLanguage = "SMS_Vrána.Languages." + (sender as MenuItem).Header.ToString();

    – ASh
    Nov 23 '18 at 14:51











  • @ASh Thats not it.. Not working for me..

    – Lukáš Vrábel
    Nov 26 '18 at 7:57



















  • Possible duplicate of In WPF how to add menu item event?

    – ASh
    Nov 23 '18 at 13:54











  • It is not, I can't add event like that. It is not working for me, i was trying it already.

    – Lukáš Vrábel
    Nov 23 '18 at 14:39











  • try strLanguage = "SMS_Vrána.Languages." + (sender as MenuItem).Header.ToString();

    – ASh
    Nov 23 '18 at 14:51











  • @ASh Thats not it.. Not working for me..

    – Lukáš Vrábel
    Nov 26 '18 at 7:57

















Possible duplicate of In WPF how to add menu item event?

– ASh
Nov 23 '18 at 13:54





Possible duplicate of In WPF how to add menu item event?

– ASh
Nov 23 '18 at 13:54













It is not, I can't add event like that. It is not working for me, i was trying it already.

– Lukáš Vrábel
Nov 23 '18 at 14:39





It is not, I can't add event like that. It is not working for me, i was trying it already.

– Lukáš Vrábel
Nov 23 '18 at 14:39













try strLanguage = "SMS_Vrána.Languages." + (sender as MenuItem).Header.ToString();

– ASh
Nov 23 '18 at 14:51





try strLanguage = "SMS_Vrána.Languages." + (sender as MenuItem).Header.ToString();

– ASh
Nov 23 '18 at 14:51













@ASh Thats not it.. Not working for me..

– Lukáš Vrábel
Nov 26 '18 at 7:57





@ASh Thats not it.. Not working for me..

– Lukáš Vrábel
Nov 26 '18 at 7:57












0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53447606%2fchanging-language-using-menu-items-in-c-sharp-wpf%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53447606%2fchanging-language-using-menu-items-in-c-sharp-wpf%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Xamarin.form Move up view when keyboard appear

Post-Redirect-Get with Spring WebFlux and Thymeleaf

Anylogic : not able to use stopDelay()