WPF.MultiLanguage
1.1.0
dotnet add package WPF.MultiLanguage --version 1.1.0
NuGet\Install-Package WPF.MultiLanguage -Version 1.1.0
<PackageReference Include="WPF.MultiLanguage" Version="1.1.0" />
paket add WPF.MultiLanguage --version 1.1.0
#r "nuget: WPF.MultiLanguage, 1.1.0"
// Install WPF.MultiLanguage as a Cake Addin #addin nuget:?package=WPF.MultiLanguage&version=1.1.0 // Install WPF.MultiLanguage as a Cake Tool #tool nuget:?package=WPF.MultiLanguage&version=1.1.0
WPF.MultiLanguage
This library is a tool designed to read JSON files and modify WPF window control properties based on the content of the files. By using this library, you can easily bind data from JSON files to WPF window controls, enabling dynamic updates to the interface. The library provides an asynchronous method, ReadJsonFileAsync
, which takes the folder path, file name of the JSON file, and an instance of the window as parameters. It then modifies the specified control properties in the window based on the content of the JSON file.
In the JSON file, you can define different types of controls (such as Label, Button, etc.), specify their names, and the property values that need to be modified. When you call the ReadJsonFileAsync
method, the library will parse the JSON file, locate the corresponding controls based on the file content, and then update their property values.
The purpose of this library is to allow WPF applications to dynamically update their interface based on external data, improving flexibility while enhancing code reusability and maintainability. By using this library, you can separate the appearance and content of the interface, making it easier to modify the interface and configure it according to external data sources.
Warn: Now we only support button and label, if you want more, please send an issue on GitHub.
Support .NET 6.0 to .NET 8.0.
Usage
MainWindow.caml.cs
using WPF.MultiLanguage;
using System.Windows;
using System.Windows.Controls;
namespace WpfApp1
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private async void Cn_ClickAsync(object sender, RoutedEventArgs e)
{
await Translate.ChangeLanguageAsync("language", "zh-cn", this);
}
}
}
MainWindow.xaml
<Window x:Class="WpfApp1.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:WpfApp1"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<Label x:Name="tlabel" Content="Label" HorizontalAlignment="Left" Margin="43,35,0,0" VerticalAlignment="Top"/>
<Button x:Name="Cn" Content="cn" HorizontalAlignment="Left" Margin="43,117,0,0" VerticalAlignment="Top" Click="Cn_ClickAsync"/>
<Button x:Name="En" Content="en" HorizontalAlignment="Left" Margin="128,127,0,0" VerticalAlignment="Top"/>
</Grid>
</Window>
Cn.json
{
"Label": {
"tlabel": "Welcome to My App"
},
"Button": {
"Cn": "zw",
"En": "yw"
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0-windows7.0 is compatible. net7.0-windows was computed. net7.0-windows7.0 is compatible. net8.0-windows was computed. net8.0-windows7.0 is compatible. |
-
net6.0-windows7.0
- Newtonsoft.Json (>= 13.0.3)
-
net7.0-windows7.0
- Newtonsoft.Json (>= 13.0.3)
-
net8.0-windows7.0
- Newtonsoft.Json (>= 13.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.