{"id":205,"date":"2022-08-31T23:12:22","date_gmt":"2022-08-31T15:12:22","guid":{"rendered":"https:\/\/www.jinhaihan.top\/WordPress\/?p=205"},"modified":"2022-08-31T23:12:25","modified_gmt":"2022-08-31T15:12:25","slug":"wpf%e4%b8%ad%e7%9a%84%e5%a4%9a%e8%af%ad%e8%a8%80%e6%94%af%e6%8c%81_%e5%8a%a8%e6%80%81%e5%88%87%e6%8d%a2%e8%af%ad%e8%a8%80","status":"publish","type":"post","link":"https:\/\/www.jinhaihan.top\/WordPress\/wpf%e4%b8%ad%e7%9a%84%e5%a4%9a%e8%af%ad%e8%a8%80%e6%94%af%e6%8c%81_%e5%8a%a8%e6%80%81%e5%88%87%e6%8d%a2%e8%af%ad%e8%a8%80\/","title":{"rendered":"wpf\u4e2d\u7684\u591a\u8bed\u8a00\u652f\u6301_\u52a8\u6001\u5207\u6362\u8bed\u8a00"},"content":{"rendered":"\n<div class=\"wp-block-jetpack-markdown\"><p>\u4e3b\u6d41\u65b9\u6cd5\u53c2\u8003\u535a\u5ba2\uff1a(\u867d\u7136\u8001\u4e86\u70b9\u4f46\u662f\u6709\u7528)<\/p>\n<blockquote>\n<p><a href=\"https:\/\/www.cnblogs.com\/horan\/archive\/2012\/04\/20\/wpf-multilanguage.html#ViaResourceDictionary\" target=\"_blank\" rel=\"noopener\">WPF\u5e94\u7528\u7a0b\u5e8f\u652f\u6301\u591a\u56fd\u8bed\u8a00\u89e3\u51b3\u65b9\u6848<\/a><\/p>\n<\/blockquote>\n<p>\u4f46\u662f\u9ed8\u8ba4\u7684\u65b9\u6848\u91cc\u8bd5\u7528\u9759\u6001\u8d44\u6e90\u4e0d\u80fd\u52a8\u6001\u5207\u6362\u8bed\u8a00\uff0c\u4ee5\u4e0b\u662f\u52a8\u6001\u5207\u6362\u8bed\u8a00\u7684\u65b9\u6cd5\uff0c\u53ef\u4ee5\u5728\u8fd0\u884c\u65f6\u5207\u6362\u8bed\u8a00\u3002<\/p>\n<h1>\u521d\u6b65\u914d\u7f6e<\/h1>\n<p>\u5728\u6587\u4ef6\u5939\u4e2d\u65b0\u5efa\u8d44\u6e90\u6587\u4ef6\uff0c\u6bd4\u5982<code>Resources\/zh.xaml<\/code>\u548c<code>Resources\/en.xaml<\/code><\/p>\n<p>\u6587\u4ef6\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n<pre><code>&lt;ResourceDictionary xmlns=&quot;http:\/\/schemas.microsoft.com\/winfx\/2006\/xaml\/presentation&quot;\n                    xmlns:x=&quot;http:\/\/schemas.microsoft.com\/winfx\/2006\/xaml&quot;\n                    xmlns:system=&quot;clr-namespace:System;assembly=mscorlib&quot;\n                    xmlns:local=&quot;clr-namespace:WPFMultiLanguage.Resources.Language&quot;&gt;\n    &lt;system:String x:Key=&quot;Testing&quot;&gt;Testing...&lt;\/system:String&gt;\n&lt;\/ResourceDictionary&gt;\n<\/code><\/pre>\n<p>\u5728app.xaml\u4e2d\u6dfb\u52a0\u6b64\u6587\u4ef6\u4e3a\u8d44\u6e90\uff0c<strong>\u6dfb\u52a0\u4e00\u4e2a\u5c31\u884c\u4e86<\/strong>\uff0c\u4f5c\u4e3a\u9ed8\u8ba4\u8bed\u8a00\u3002\u6700\u7ec8<code>app.xaml<\/code>\u5dee\u4e0d\u591a\u662f\u8fd9\u6837\u7684\uff1a<\/p>\n<pre><code>&lt;Application\n    x:Class=&quot;DeviceInfoSyncClient.App&quot;\n    xmlns=&quot;http:\/\/schemas.microsoft.com\/winfx\/2006\/xaml\/presentation&quot;\n    xmlns:x=&quot;http:\/\/schemas.microsoft.com\/winfx\/2006\/xaml&quot;\n    xmlns:ui=&quot;http:\/\/schemas.lepo.co\/wpfui\/2022\/xaml&quot;\n    DispatcherUnhandledException=&quot;OnDispatcherUnhandledException&quot;\n    Exit=&quot;OnExit&quot;\n    Startup=&quot;OnStartup&quot;&gt;\n    &lt;Application.Resources&gt;\n        &lt;ResourceDictionary&gt;\n            &lt;ResourceDictionary.MergedDictionaries&gt;\n                &lt;!--Default Language File--&gt;\n                &lt;ResourceDictionary Source=&quot;\/DeviceInfoSyncClient;component\/Resources\/en_us.xaml&quot;\/&gt;\n                -------\u5176\u4ed6\u7684\u8d44\u6e90\u6587\u4ef6\n            &lt;\/ResourceDictionary.MergedDictionaries&gt;\n        &lt;\/ResourceDictionary&gt;\n    &lt;\/Application.Resources&gt;\n&lt;\/Application&gt;\n\n<\/code><\/pre>\n<p>\u5728\u7a0b\u5e8f\u4e2d\u4f7f\u7528\u65f6\uff0c\u9700\u8981\u5728xaml\u4e2d\u83b7\u53d6\u7684\u8bdd\uff0c\u9700\u8981\u4f7f\u7528<code>DynamicResource<\/code>\u4ee5\u5e94\u5bf9\u52a8\u6001\u4fee\u6539\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre><code>&lt;Grid&gt;\n        &lt;StackPanel&gt;\n            &lt;TextBlock Text=&quot;{DynamicResource Greeting}&quot;\/&gt;\n\n            &lt;Button Content=&quot;{DynamicResource Language}&quot; Width=&quot;100&quot; Height=&quot;35&quot; Click=&quot;SwitchButton_Click&quot;\/&gt;\n        &lt;\/StackPanel&gt;\n    &lt;\/Grid&gt;\n<\/code><\/pre>\n<p>\u5728cs\u6587\u4ef6\u4e2d\u52a8\u6001\u83b7\u53d6\u7684\u8bdd\uff0c\u5c31\u76f4\u63a5<\/p>\n<pre><code> (string)Application.Current.FindResource(&quot;Testing&quot;)\n<\/code><\/pre>\n<h1>\u52a8\u6001\u5207\u6362<\/h1>\n<p>\u56e0\u4e3a\u5df2\u7ecf\u5c06\u4e00\u4e2a\u6587\u4ef6\u4f5c\u4e3a\u8d44\u6e90\u5b57\u5178\u4e86\uff0c\u5176\u4ed6\u7684\u8bed\u8a00\u7684\u8d44\u6e90\u6587\u4ef6\u6ca1\u6709\u7528\u5230\uff0c\u8fd9\u91cc\u9700\u8981\u52a8\u6001\u66ff\u6362\u4e00\u4e0b\uff1a<\/p>\n<pre><code> public static void ChangeLanguage(string newLang)\n{\n    ResourceDictionary dict = new ResourceDictionary();\n    \/\/\u4e0b\u9762\u6362\u6210\u4f60\u60f3\u8981\u7684\u8d44\u6e90\u5b57\u5178\n    dict.Source = new Uri(@&quot;Resources\\zh_cn.xaml&quot;, UriKind.Relative);\n    Application.Current.Resources.MergedDictionaries[0] = dict;\n}\n<\/code><\/pre>\n<\/div>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":206,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[21,7],"tags":[],"class_list":["post-205","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-wpf","category-bolg"],"jetpack_publicize_connections":[],"jetpack-related-posts":[],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"https:\/\/i0.wp.com\/www.jinhaihan.top\/WordPress\/wp-content\/uploads\/2022\/08\/pexels-photo-6045344.jpeg?fit=1880%2C1245&ssl=1","_links":{"self":[{"href":"https:\/\/www.jinhaihan.top\/WordPress\/wp-json\/wp\/v2\/posts\/205","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jinhaihan.top\/WordPress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jinhaihan.top\/WordPress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jinhaihan.top\/WordPress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jinhaihan.top\/WordPress\/wp-json\/wp\/v2\/comments?post=205"}],"version-history":[{"count":1,"href":"https:\/\/www.jinhaihan.top\/WordPress\/wp-json\/wp\/v2\/posts\/205\/revisions"}],"predecessor-version":[{"id":207,"href":"https:\/\/www.jinhaihan.top\/WordPress\/wp-json\/wp\/v2\/posts\/205\/revisions\/207"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.jinhaihan.top\/WordPress\/wp-json\/wp\/v2\/media\/206"}],"wp:attachment":[{"href":"https:\/\/www.jinhaihan.top\/WordPress\/wp-json\/wp\/v2\/media?parent=205"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jinhaihan.top\/WordPress\/wp-json\/wp\/v2\/categories?post=205"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jinhaihan.top\/WordPress\/wp-json\/wp\/v2\/tags?post=205"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}