开发者

wpf how to update Window

I have made my application multilingual. It changes it's language when you click the corresponding menuitem. This works fine but my problem comes when my parent window doesn't change it's language (menu is in parent window). All child windows change their language. Is there any way to force window to load again? I have done my application with resx-files and also checked that Thread.CurrentThread.CurrentCulture and Thread.CurrentThread.CurrentUICulture are changed when menuitem is clicked.

Edit:

I have made my own class to do the multilingual part and it is an adaptation from this article's approach: WPF Runtime Localization, it works. Here is a part of my XAML code to show the databindings:

<Window x:Class="Multilingual.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:properties="clr-namespace:Multilingual.Properties" 
    Height="350" Width="300" Name="mainWindow" ResizeMode="CanMinimize" SizeToContent="Manual" Closing="mainWindow_Closing" KeyDown="mainWindow_KeyDown">

and

 <Menu Height="22" Name="menu" Width="{Binding ElementName=mainWindow, Path=Width}" HorizontalAlignment="Left" VerticalAlignment="Top" Background="Snow" BorderThickness="2">
        <Menu.BitmapEffect>
            <DropShadowBitmapEffect />
        </Menu.BitmapEffect>
        <MenuItem Header="{x:Static properties:Resources.Menu}">
            <MenuItem Header="{x:Static properties:Resources.Language}" >
                <MenuItem Header="{x:Static pro开发者_StackOverflowperties:Resources.Deutsch}" Name="itemDeutsch" Click="menuItem_Click" />
                <MenuItem Header="{x:Static properties:Resources.English}" Name="itemEnglish" Click="menuItem_Click" />
            </MenuItem>
            <MenuItem Header="{x:Static properties:Resources.Exit}" Click="itemExit_Click"/>
        </MenuItem>
    </Menu>

So I think it would be enough if I would be able to update the window somehow.


WPF: How to change the CurrentUICulture at runtime


I found a solution. I changed my databindings to look like this:

<MenuItem Header="{Binding Path=Menu, Source={StaticResource Resources}}">

Where "Menu" corresponds the MenuItem's name in resx-file.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜