开发者

How to force MarkupExtension to bind again

I want to force my custom extension to bind again when my language change:

[MarkupExtensionReturnType(typeof(string))]
public class TranalstionExtension : MarkupExtension
{
    public override object ProvideValue(IServiceProvider serviceProvider)
    {
        return Translator.Translate(this.Translate);
    }

    public string Translate { get; set; }
}

in usage:

<Button Content="{t:Tranalstion Translate=plus}"/>
开发者_Python百科

I'm changing the language on the same Window so now it should return into property different translation, how to force MarkupExtension to do this but not only for Content property but for all occurrence of my extension mechanism on window.


Your data source has to implement the INotifyPropertyChanged event.

public override object ProvideValue( IServiceProvider serviceProvider )
{
    var binding = new Binding( "Value" )
    {
        Source = new TranslationData( this.Translate )
    };
    return binding.ProvideValue( serviceProvider );
}

TranslationData then has to take care of getting informed about a langauge change and fire the PropertyChanged event.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜