简体   繁体   中英

How get the a static resource value at DesignTime in MarkupExtension?

I Succeeded in Creating my own MarkupExtension i named it "GtringResource" and it is working well, but in design mode didn't.

I have the following code in 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;
}

I want to return the value that should appear at runtime cause i retrieve the value from a merged dictionary, looks like in xaml:

<Button x:Name="downloadButton"  Content="{intllectual:GtringResource downloadGtring}"/>

I tried this but it is not helpful:

/// ... when detect desingmode "IsDesingMode"
return ((Gtring)Application.Current.TryFindResource(GtringKey)).en;
/// ...

尝试:

public class ResourceExtension : StaticExtension

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM