wpf - How to combine binding from custom data context with custom markup -
i want combine binding custom data context contains viewmodel class , resourceprovider class. custom data context set window datacontext.
i use way:
<button x:name="btnshow" content="show" command="{binding view.handleshow}"/>
which view property datacontext. want use localization custom data context using minimum markup , set resourceprovider other source in code created own data context
is there possibility in similar line of code:
<textblock text="{binding res.key=test}" />
my resource provider inherits markup extension 1 property: key.
thanks advice
you can create custom markup extension using following code :
public class localizedbinding : markupextension { public string key { get; set; } public override object providevalue(iserviceprovider serviceprovider) { iprovidevaluetarget target = (iprovidevaluetarget)serviceprovider.getservice(typeof(iprovidevaluetarget)); //use target.targetobject , target.targetproperty provide value based on key } }
and use :
<textblock text="{local:localizedbinding key=somekey}" />
Comments
Post a Comment