diff --git a/demo/Semi.Avalonia.Demo/App.axaml b/demo/Semi.Avalonia.Demo/App.axaml index 07879bb..f63be9d 100644 --- a/demo/Semi.Avalonia.Demo/App.axaml +++ b/demo/Semi.Avalonia.Demo/App.axaml @@ -1,9 +1,10 @@ + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:semi="https://irihi.tech/semi"> - + diff --git a/src/Semi.Avalonia/AssemblyInfo.cs b/src/Semi.Avalonia/AssemblyInfo.cs new file mode 100644 index 0000000..851b612 --- /dev/null +++ b/src/Semi.Avalonia/AssemblyInfo.cs @@ -0,0 +1,4 @@ +using Avalonia.Metadata; + +[assembly:XmlnsPrefix("https://irihi.tech/semi", "semi")] +[assembly:XmlnsDefinition("https://irihi.tech/semi", "Semi.Avalonia")] \ No newline at end of file diff --git a/src/Semi.Avalonia/Controls/ManagedFileChooser.axaml b/src/Semi.Avalonia/Controls/ManagedFileChooser.axaml index 7767672..0ce233c 100644 --- a/src/Semi.Avalonia/Controls/ManagedFileChooser.axaml +++ b/src/Semi.Avalonia/Controls/ManagedFileChooser.axaml @@ -80,11 +80,11 @@ + Watermark="{DynamicResource STRING_CHOOSER_FILE_NAME}" /> - OK - + Command="{Binding Ok}" + Content="{DynamicResource STRING_CHOOSER_DIALOG_OK}" /> + Command="{Binding Cancel}" + Content="{DynamicResource STRING_CHOOSER_DIALOG_CANCEL}" /> + File name + Show hidden flies + OK + Cancel + \ No newline at end of file diff --git a/src/Semi.Avalonia/Locale/zh-cn.axaml b/src/Semi.Avalonia/Locale/zh-cn.axaml new file mode 100644 index 0000000..f4fce56 --- /dev/null +++ b/src/Semi.Avalonia/Locale/zh-cn.axaml @@ -0,0 +1,7 @@ + + 文件名 + 显示隐藏文件 + 确认 + 取消 + \ No newline at end of file diff --git a/src/Semi.Avalonia/Themes/Index.axaml b/src/Semi.Avalonia/Themes/Index.axaml index 86c4758..1b36b00 100644 --- a/src/Semi.Avalonia/Themes/Index.axaml +++ b/src/Semi.Avalonia/Themes/Index.axaml @@ -1,4 +1,4 @@ - + @@ -9,6 +9,7 @@ + diff --git a/src/Semi.Avalonia/Themes/Index.axaml.cs b/src/Semi.Avalonia/Themes/Index.axaml.cs new file mode 100644 index 0000000..a2646cf --- /dev/null +++ b/src/Semi.Avalonia/Themes/Index.axaml.cs @@ -0,0 +1,55 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using Avalonia.Controls; +using Avalonia.Markup.Xaml; +using Avalonia.Styling; + +namespace Semi.Avalonia; + +public class SemiTheme: Styles +{ + private static readonly Dictionary _localeToResource = new() + { + { new CultureInfo("zh-CN"), "avares://Semi.Avalonia/Locale/zh-CN.axaml" }, + { new CultureInfo("en-US"), "avares://Semi.Avalonia/Locale/en-US.axaml" }, + }; + + private readonly IServiceProvider? sp; + public SemiTheme(IServiceProvider? provider = null) + { + sp = provider; + AvaloniaXamlLoader.Load(provider, this); + } + + private CultureInfo? _locale; + public CultureInfo? Locale + { + get => _locale; + set + { + _locale = value; + var resource = TryGetLocaleResource(value); + var d = AvaloniaXamlLoader.Load(sp, new Uri(resource)) as ResourceDictionary; + if (d is null) return; + foreach (var kv in d) + { + this.Resources.Add(kv); + } + } + } + + private static string TryGetLocaleResource(CultureInfo? locale) + { + if (locale is null) + { + return _localeToResource[new CultureInfo("zh-CN")]; + } + + if (_localeToResource.TryGetValue(locale, out var resource)) + { + return resource; + } + return _localeToResource[new CultureInfo("zh-CN")]; + } +} \ No newline at end of file