我已按照文章:Localization of a WPF application using a custom MarkupExtension進行了國際化我的應用。TranslationByMarkupExtension:在啓動時使用自定義值填充MainApplication.xaml
在我MainWindow.xaml我有:
<Button x:Name="ServiceButton" Content="{l:Translate service.button.start}" Click="toggle_service_click" />
正如你所看到的翻譯標記{1:翻譯service.button.start}寫入檢索串service.button.start在我當前區域的資源文件時,應用程序加載,但如果服務已經啓動標記字符串應該是service.button.stop
因此,在實踐中,whene我跑我的應用程序,如果服務開始:
<Button x:Name="ServiceButton" Content="{l:Translate service.button.stop}" Click="toggle_service_click" />
否則
<Button x:Name="ServiceButton" Content="{l:Translate service.button.start}" Click="toggle_service_click" />
我怎麼能在這之前translationManager XAML文件直接設置corret標記「對飛」解析呢?
編輯: 我已經tryed將其綁定在我的DataContext像這樣: 的DataContext
public object ServiceTplString
{
get
{
var isr = ServiceHandler.Instance.serviceIsRunning("service_alias", "service_name");
return "{l:Translate service.button." + ((isr) ? "stop" : "start") + "}";
}
}
MainApplication.xaml:
<Button x:Name="ServiceButton" Content="{Binding ServiceTplString}" Click="toggle_service_click" />
但不工作..