Content of controls can be localized using Resource files, just as this is possible in classes. For XAML there is a specific syntax, that is different between a C# and a VB application.
The steps are:
PublicVbMyResourcesResXFileCodeGenerator
.<Window x:Class="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:WpfApplication1"
xmlns:my="clr-namespace:WpfApplication1.My.Resources"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid>
<StackPanel>
<Label Content="{Binding Source={x:Static my:Resources.MainWindow_Label_Country}}" />
</StackPanel>
</Grid>
By default the Custom Tool property for a VB resource file is VbMyResourcesResXFileCodeGenerator
. However, with this code generator the view (XAML) will not be able to access the resources. To solve this problem add Public
before the Custom Tool property value.
To select the Resources.resx file in a VB WPF project:
<Window x:Class="WpfApplication2.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:WpfApplication2"
xmlns:resx="clr-namespace:WpfApplication2.Properties"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid>
<StackPanel>
<Label Content="{Binding Source={x:Static resx:Resources.MainWindow_Label_Country}}"/>
</StackPanel>
</Grid>