独自の MarkupExtension の作成に成功しました 「GtringResource」という名前を付けましたが、うまく機能していますが、デザイン モードでは機能しませんでした。
ProvideValue(IServieProvider ServiceProvider) に次のコードがあります。
public override object ProvideValue(IServiceProvider serviceProvider)
{
if (System.ComponentModel.DesignerProperties.GetIsInDesignMode(new DependencyObject()))
{
return "design mode";
}
StaticResourceExtension staticResourceExtension = new StaticResourceExtension(this.GtringKey);
var gtringresource = staticResourceExtension.ProvideValue(serviceProvider) as Gtring;
return gtringresource.en;
}
実行時に表示される値を返したいのですが、マージされた辞書から値を取得するため、xaml のようになります。
<Button x:Name="downloadButton" Content="{intllectual:GtringResource downloadGtring}"/>
私はこれを試しましたが、役に立ちません:
/// ... when detect desingmode "IsDesingMode"
return ((Gtring)Application.Current.TryFindResource(GtringKey)).en;
/// ...